Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading Blazor WebAssembly to 3.1.0-preview4.19579.2 leads to an error: Could not find 'BlazorExtensions' in 'window'. #66

Closed
szmalec opened this issue Dec 12, 2019 · 10 comments

Comments

@szmalec
Copy link

szmalec commented Dec 12, 2019

Recently I tried to update my blazor wasm project (which uses Blazor.Extensions.SignalR v1.1.0-preview3) to latest 3.1.0-preview4.19579.2 Blazor version.
After updating, an error began to appear in browser console:

Could not find 'BlazorExtensions' in 'window'. Error: Could not find 'BlazorExtensions' in 'window'.
 at http://localhost:7258/_framework/blazor.webassembly.js:1:8937
 at Array.forEach (<anonymous>)
 at p (http://localhost:7258/_framework/blazor.webassembly.js:1:8898)
 at Object.invokeJSFromDotNet (http://localhost:7258/_framework/blazor.webassembly.js:1:9470)
 at _mono_wasm_invoke_js_marshalled (http://localhost:7258/_framework/wasm/mono.js:1:165750)
 at wasm-function[6221]:0x11936a
 at wasm-function[1431]:0x402ee
 at wasm-function[636]:0x147cf
 at wasm-function[636]:0x19ae2
 at wasm-function[4996]:0xeb135

It is probably due to latest changes related to static assets in libraries - as we can see at https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-core-3-1/

Support for static assets in libraries when publishing
Standalone Blazor WebAssembly apps now support static assets from Razor class libraries both during development and when publishing. This applies to both standalone Blazor WebAssembly apps and ASP.NET Core hosted apps. Static assets are consumed from referenced libraries using the path prefix: _content/{LIBRARY NAME}/.

There is also PR @ AspNetCore src repo: https://github.com/aspnet/AspNetCore/pull/17353/files
Problem is also reported in several other projects which uses *.js static assets.

Initially I have also tried to update Blazor.Extensions.SignalR to 3.1.0-preview4.19579.2 and the same Could not find 'BlazorExtensions' in 'window' occured when Blazor.Extensions.SignalR.Test.Server started.

I have discovered some differences between old build output and new build output, eg.:

[old - netstandard2.0]

  • there WAS: test\Blazor.Extensions.SignalR.Test.Client\bin\Debug\netstandard2.0\dist\_content\Blazor.Extensions.SignalR.JS
  • there WAS: "jsReferences": [ "_content/Blazor.Extensions.SignalR.JS" ] entry in test\Blazor.Extensions.SignalR.Test.Client\bin\Debug\netstandard2.0\dist\_framework\blazor.boot.json

[new - netstandard2.1]

  • test\Blazor.Extensions.SignalR.Test.Client\bin\Debug\netstandard2.1\dist\_content\Blazor.Extensions.SignalR.JS does NOT exists
  • test\Blazor.Extensions.SignalR.Test.Client\bin\Debug\netstandard2.1\dist\_framework\blazor.boot.json does NOT contain "jsReferences": [ "_content/Blazor.Extensions.SignalR.JS" ] entry

I have forked Blazor.Extensions.SignalR repo and I will try to prepare workaround...

szmalec pushed a commit to szmalec/SignalR that referenced this issue Dec 12, 2019
…aded after update to 3.1.0-preview4.19579.2 (lead to error: Could not find 'BlazorExtensions' in 'window'. Error: Could not find 'BlazorExtensions' in 'window'). See BlazorExtensions#66 for more details.
@szmalec
Copy link
Author

szmalec commented Dec 12, 2019

In szmalec@0d8fe51 you can see modified Blazor.Extensions.SignalR version which works OK after update to 3.1.0-preview4.19579.2.
As you probably discover there are some drawbacks:

It looks that previously existed entry <EmbeddedResource Include="wwwroot\**\*.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" /> in Blazor.Extensions.SignalR.JS.csproj is not taken into account (is not used)?

Am I wrong at any of above points?


So if anyone wants to have 3.1.0-preview4.19579.2 and Blazor.Extensions.SignalR then can use my temporary solution.
Otherwise maybe it would be better to wait, because there are some currently unresolved issues which have "asset" in title, eg. for blazor-wasm-3.2-preview1...

szmalec added a commit to szmalec/SignalR that referenced this issue Dec 12, 2019
…aded after update to 3.1.0-preview4.19579.2 (lead to error: Could not find 'BlazorExtensions' in 'window'. Error: Could not find 'BlazorExtensions' in 'window'). See BlazorExtensions#66 for more details.
@AlexanderJohnston
Copy link

AlexanderJohnston commented Dec 23, 2019

I cannot find the Blazor.Extensions.SignalR.JS file to put into my _content folder. Where are you guys getting that? Everything makes sense except for that piece of the puzzle.

This issue is blocking my team from doing any work right now. Do we have any fixes? I tried following what you guys are talking about up above but I cannot reproduce your fix.

@TroelsL
Copy link

TroelsL commented Dec 27, 2019

Ran into the same issue, even managed to replace the BlazorExtensions.Storage with another solution before finding out what the root issue was.

I'd very much also appreciate a bit more elaborate (or dumbed down, if you will) set of workaround steps if anyone is able and willing. I haven't been able to locate another solution for doing SignalR in Blazor WASM.

@coj337
Copy link

coj337 commented Dec 29, 2019

It's just a temporary fix until the proper patch is merged in but you can compile the js manually and reference that from your index.html
(Here's mine if you're lazy, just change the extension to js blazor.extensions.signalr.txt)

@cmoski
Copy link

cmoski commented Jan 7, 2020

I was able to get around this issue by creating a new Razor Class Library, and adding: https://github.com/BlazorExtensions/SignalR/files/4007658/blazor.extensions.signalr.txt (renamed to .js) to RazorClasssLibrary\wwwroot\Blazor.Extensions.SingalR.js and adding the following:

<script type="text/javascript" src="_content/RazorClasssLibrary/Blazor.Extensions.SignalR.js"></script> to index.html

Once I did this, it appears the websocket was at least connecting. (Although I don't have more information on if there is a better place to put this reference.)

@PierpaoloBattaglioneSpecifi
Copy link

PierpaoloBattaglioneSpecifi commented Jan 16, 2020

Actually with all the changes made in @szmalec's branch everything works, even in WebAssembly. Is this project still maintained? Can we open a PR?

Are we waiting for blazor-wasm-3.2-preview1 to be released?

@EugeneScully
Copy link

Are we waiting for blazor-wasm-3.2-preview1 to be released?

It looks like a SignalR client is scheduled for 3.2-preview3:
https://github.com/dotnet/aspnetcore/milestone/81
dotnet/aspnetcore#13503

@szmalec
Copy link
Author

szmalec commented Jan 29, 2020

It looks that we can now forget about problems with Blazor Extensions SignalR and use Microsoft.AspNetCore.SignalR.Client directly - see "Support for the .NET SignalR client" section @ https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-preview-1-release-now-available/

@galvesribeiro
Copy link
Member

@szmalec Yes, the SignalR client is now supported on WebAssembly as expected.

One quick note... Before you blame "Blazor Extensions SignalR problems", please read the real reason why it has problems before start attacking others.

For future readers, the problem is caused because Blazor changed the way it deals with static content (CSS/JS) and that breaks every single extension out there making components useless.

As stated here we are working on bring a solution for this issue that doesn't requires manual interaction with JS/CSS files by the final user otherwise, it will not make any sense at all. It beats the purpose of a NuGet package in its essence.

@szmalec
Copy link
Author

szmalec commented Jan 29, 2020

@galvesribeiro
I didn't want it to sound like that. I know that SignalR Blazor Extensions should not be blamed for problems resulting from changes in the WASM Blazor - which is still in preview phase.
I just hoped that using the official SignalR client could be a better idea to bypass the likely temporary issues reported in this issue.

I know that SignalR Blazor Extensions is a piece of awesome work - thank you for your commitment and willingness to share the results of your hard work with the community!!

Now I also know that the recommendation of switching to the official Microsoft.AspNetCore.SignalR.Client in the WASM Blazor apps was not necessarily a good move (at least for now when blazor wasm is not officialy production ready), because after migration I encountered other problems (related to JWT auth) which I mention here (comment still not moderated - so not publicly available) ;)

So again - we should remember that Blazor WASM is still an alpha phase;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants