MatBlazor - Embedded resource files not outputting

606 Views Asked by At

I am using MatBlazor 2.6.0 in a server side blazor project. I did the following steps:

  • Added MatBlazor to the project (2.6.0)
  • Included @Using MatBlazor in my _Imports.razor file
  • Added the static file to _Hosts.cshtml

When I run the project I get an error:

 Microsoft.JSInterop.JSException: Could not find 'matBlazor' in 'window'.

When I check the view source in the browser, I see there is a reference:

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

But when I check the contents of that .js file it is empty, any idea on what I could be doing wrong here?

2

There are 2 best solutions below

0
On

I had to change the ASPNETCORE_ENVIRONMENT environment variable from "Local" to "Development" and it magically started working... still looking for why.

see https://github.com/SamProf/MatBlazor/issues/375#issuecomment-852946500 for details

0
On

If your _Host.cshtml head looks like this:

<head>
    ...

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

    ...
</head>

Then maybe the problem lies with how it was added to the project. Did you use the Nuget Package manager in Visual Studio? It is strange for the file to be empty I agree.