ASP.NET Core 8 and Blazor Web Assembly application runtimeconfig

1.7k views Asked by At

I am following this tutorial https://dotnet.microsoft.com/en-us/learn/aspnet/blazor-tutorial/run which builds a very basic Blazor app. However the project won't run on ASP.NET Core 8. Could you please help find out why the <app>runtimeconfig.json file does not get generated when the Blazor project is built? This is needed because otherwise the project won't run. The project is built successfully but I can not run it.

The error that I get is:

WasmAppHost --use-staticwebassets --runtime-config runtimeconfig.json
Error: Cannot find runtime config at /bin/Debug/net8.0/

I have tried setting the property GenerateRuntimeConfigDevFile to true in the .csproj file as described here: https://learn.microsoft.com/en-us/dotnet/core/runtime-config/

but still the json file does not get created.

I have tried manually creating it using the schema found here: https://gist.github.com/natemcmaster/0bdee16450f8ec1823f2c11af880ceeb but I get error about missing WasmHostProperties. There must be something specific to wasm applications.

I came up with this:

{
    "runtimeOptions": {
       "tfm": "net8.0",
       "frameworks": [
           {
               "name": "Microsoft.NETCore.App",
               "version": "8.0.0"
           },
           {
               "name": "Microsoft.AspNetCore.App",
               "version": "8.0.0"
           }
       ],
       "configProperties": {
           "System.GC.Server": true,
           "System.Reflection.NullabilityInfoContext.IsSupported": true,
           "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
       },
       "wasmHostProperties": {
           "webServerPort":"7238",
           "perHostConfig": [
        {
            "name": "wasmAppHost",
            "host-args": [
                "--experimental-wasm-simd", 
                "--experimental-wasm-eh" 
            ]
        }
    ]
}
}
}

However I believe this file should be automatically be generated.

I am currently upgrading Visual Studio to version 17.8.2 due to a warning saying that VS version 17.7 cannot target .NET version 8 or above. Will keep you updated in case this resolves the issue with the json file.

I also get a warning regarding compiler versions, I am not sure if it is related:

Warning CS9057 The analyzer assembly 'C:\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\8.0.0\analyzers\dotnet\cs\Microsoft.AspNetCore.App.Analyzers.dll' references version '4.8.0.0' of the compiler, which is newer than the currently running version '4.7.0.0'. WebAppAuthorization C:\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\8.0.0\analyzers\dotnet\cs\Microsoft.AspNetCore.App.Analyzers.dll 1 Active

Could you please give some advice?

Thank you in advance.

3

There are 3 answers

0
Robert McLaws On BEST ANSWER

I beat my head against the walls for HOURS across several days with this one, and I couldn't figure it out. Until I diffed it with another Blazor project.

The reason this happens is because you have not included the Blazor DevServer NuGet package in the WASM project.

Digging into the details, that package has a different set of MSBuild targets that trigger an entirely different set of RunArguments that don't require a runtimeconfig.json file at all.

Simply add this to your project:

<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.*-*" PrivateAssets="all" />

And you'll be up and running again.

0
TechQuestion On

I think it is the way I am referencing nuget packages and the sdk .net version (for server) and the sdk for blazorwebassembly version (client) I am using (in csproj/project tag ). By recreating the project from the beginning, the app runs successfully even though the runtimeconfig file for the wasm is still not generated. Nevertheless, there is no need to spend time on this since the app is now running. Thank you

0
Asmussen On

I had the same error. I had to set the "BlazorApp" project (not the blazorapp.client) as the startup project.