Matblazor: Exception after Upgrading MatBlazor to 2.0

Created on 10 Dec 2019  路  8Comments  路  Source: SamProf/MatBlazor

I had MatBlazor 1.1 working in .NET Core 3.0 Server Side mode (not even prerendered)
I upgraded my project to .NET Core 3.1 and it still works fine.

After upgrading to MatBlazor 2.0 the following exception got thrown.
Any idea where to look?

Microsoft.JSInterop.JSException: Could not find 'matBlazor' in 'window'.
Error: Could not find 'matBlazor' in 'window'.
at https://localhost:5001/_framework/blazor.server.js:8:30748
at Array.forEach ()
at p (https://localhost:5001/_framework/blazor.server.js:8:30709)
at https://localhost:5001/_framework/blazor.server.js:8:31416
at new Promise ()
at e.beginInvokeJSFromDotNet (https://localhost:5001/_framework/blazor.server.js:8:31390)
at https://localhost:5001/_framework/blazor.server.js:1:19202
at Array.forEach ()
at e.invokeClientMethod (https://localhost:5001/_framework/blazor.server.js:1:19173)
at e.processIncomingData (https://localhost:5001/_framework/blazor.server.js:1:17165)
at Microsoft.JSInterop.JSRuntime.InvokeWithDefaultCancellationT
at MatBlazor.BaseMatComponent.JsInvokeAsyncT
at MatBlazor.BaseMatAppBar.OnFirstAfterRenderAsync()
at MatBlazor.BaseMatComponent.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

Most helpful comment

Please clear broswer cache (not cookies only).
Then try add js script after blazor js.
Like this

<script src="_framework/blazor.webassembly.js"></script>

<!-- load remaining JS after blazor boot loads -->
<script src="_content/MatBlazor/dist/matBlazor.js"></script>

All 8 comments

oh, seems this works better, but not perfect yet.
instead of @Html.EmbeddedBlazorContent()

I had to do:

<script src="_content/MatBlazor/dist/matBlazor.js"></script>

Work for me when I add the script in _Host.cshtml
<script src="_content/MatBlazor/dist/matBlazor.js"></script>

<script src="_content/MatBlazor/dist/matBlazor.js"></script>

this is not work for me , right now Im using 2.3.0 version Matblazor, i just got basic html button in my page not proper matblazor button and I also use this <script src="_content/blazor.extensions.logging.js"></script> , but now worked !!

I also can't make it work with server-side blazor.
I get the following exception:
Exception thrown: 'Microsoft.JSInterop.JSException' in MatBlazor.dll
Exception thrown: 'Microsoft.JSInterop.JSException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSException' in System.Private.CoreLib.dll
Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: Could not find 'matBlazor' in 'window'.
Error: Could not find 'matBlazor' in 'window'.
at http://localhost:5000/_framework/blazor.server.js:8:30748
at Array.forEach ()
at p (http://localhost:5000/_framework/blazor.server.js:8:30709)
at http://localhost:5000/_framework/blazor.server.js:8:31416
at new Promise ()
at e.beginInvokeJSFromDotNet (http://localhost:5000/_framework/blazor.server.js:8:31390)
at http://localhost:5000/_framework/blazor.server.js:1:19202
at Array.forEach ()
at e.invokeClientMethod (http://localhost:5000/_framework/blazor.server.js:1:19173)
at e.processIncomingData (http://localhost:5000/_framework/blazor.server.js:1:17165)

Microsoft.JSInterop.JSException: Could not find 'matBlazor' in 'window'.
Error: Could not find 'matBlazor' in 'window'.
at http://localhost:5000/_framework/blazor.server.js:8:30748
at Array.forEach ()
at p (http://localhost:5000/_framework/blazor.server.js:8:30709)
at http://localhost:5000/_framework/blazor.server.js:8:31416
at new Promise ()
at e.beginInvokeJSFromDotNet (http://localhost:5000/_framework/blazor.server.js:8:31390)
at http://localhost:5000/_framework/blazor.server.js:1:19202
at Array.forEach ()
at e.invokeClientMethod (http://localhost:5000/_framework/blazor.server.js:1:19173)
at e.processIncomingData (http://localhost:5000/_framework/blazor.server.js:1:17165)
at Microsoft.JSInterop.JSRuntime.InvokeWithDefaultCancellationT
at MatBlazor.BaseMatComponent.JsInvokeAsyncT
at MatBlazor.MatExpansionPanelSummary.b__9_0()
at MatBlazor.BaseMatComponent.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'rDgaIspfz7gDk7I1npRRxx9uInYn1znErwmzQ7Dhiow'.

It broke for me also when I upgraded.
I am upgrading my Blazor(3.2.0-preview3.20168.3) and VS 2019(Version 16.6.0 Preview 2.1) and .Net Core(3.1.300-preview-015048) and now I am getting the "Could not find 'matBlazor' in 'window'. in my Blazor Client / WebAssembly project"
I added the matBlazor.css to the head section and matBlazor.js to the end of the body section of my index.html per earlier discussion. I don't have any .cshtml files.
I also removed and added back the NuGet package for MatBlazor.
What else should I try?

Please clear broswer cache (not cookies only).
Then try add js script after blazor js.
Like this

<script src="_framework/blazor.webassembly.js"></script>

<!-- load remaining JS after blazor boot loads -->
<script src="_content/MatBlazor/dist/matBlazor.js"></script>

How does this work in a Blazor Web Assembly? Do you simply use the index.html under wwwroot?

@mclintsmanNAF Yup

For everyone following: In the head section, put this:

    <script src="_content/MatBlazor/dist/matBlazor.js"></script>
    <link href="_content/MatBlazor/dist/matBlazor.css" rel="stylesheet" />

Be aware that the root folder is _content (meaning I want to take files from a referenced package)not _framework if you accidentally copy pasted the webassembly js.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BenjaminCharlton picture BenjaminCharlton  路  3Comments

snerting picture snerting  路  3Comments

lkmcelik picture lkmcelik  路  4Comments

GioviQ picture GioviQ  路  6Comments

Mercurial picture Mercurial  路  5Comments