A TypeLoadException is thrown when attempting to start a Blazor server side web application that is created using the default VS 2019 templates.
The example web application should start without any exceptions being thrown
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:1693/
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.Endpoints.EndpointHttpContextExtensions' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at Microsoft.AspNetCore.SpaServices.SpaDefaultPageMiddleware.<>c__DisplayClass0_0.b__0(HttpContext context, Func 1 next) at Microsoft.AspNetCore.Builder.UseExtensions.<>c__DisplayClass0_1.<Use>b__1(HttpContext context) at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) info: Microsoft.AspNetCore.Hosting.Diagnostics[2] Request finished in 295.373ms 500 text/html; charset=utf-8 info: Microsoft.AspNetCore.Hosting.Diagnostics[1] Request starting HTTP/1.1 GET http://localhost:1693/favicon.ico fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.Endpoints.EndpointHttpContextExtensions' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. at Microsoft.AspNetCore.SpaServices.SpaDefaultPageMiddleware.<>c__DisplayClass0_0.<Attach>b__0(HttpContext context, Func
1 next)
at Microsoft.AspNetCore.Builder.UseExtensions.<>c__DisplayClass0_1.
dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview6-012264
Commit: be3f0c1a03Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:Program Filesdotnetsdk3.0.100-preview6-012264Host (useful for support):
Version: 3.0.0-preview6-27804-01
Commit: fdf81c6faf.NET Core SDKs installed:
1.1.13 [C:Program Filesdotnetsdk]
1.1.14 [C:Program Filesdotnetsdk]
2.1.602 [C:Program Filesdotnetsdk]
2.1.604 [C:Program Filesdotnetsdk]
2.1.700 [C:Program Filesdotnetsdk]
2.2.202 [C:Program Filesdotnetsdk]
2.2.204 [C:Program Filesdotnetsdk]
2.2.300 [C:Program Filesdotnetsdk]
3.0.100-preview6-012264 [C:Program Filesdotnetsdk].NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.9 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.3 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview6.19307.2 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.15 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.NETCore.App 1.0.16 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.NETCore.App 1.1.12 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.NETCore.App 1.1.13 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview6-27804-01 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview6-27804-01 [C:Program FilesdotnetsharedMicrosoft.WindowsDesktop.App]
This app doesn’t look like it was created using the default template, since the stack trace implies it uses SpaDefaultPageMiddleware. The current templates don’t use that.
Are you trying to upgrade an existing application?
No... It's the first Blazor web app I'm creating using VS 2019 and I did nothing else except the reproduce steps I mentioned in the ticket. I've tried to create another application from the template, same issue.
You can see all steps on this gif. Currently using VS 2019 Enterprise, version 16.1.3
Same for me with new project...
Created new .NET Core hosted Client Side Blazor project from Visual Studio as Nuno is doing.
Looks like the Client Side Blazor only template runs out of the box - the Server hosted one does not work.
I was confused because the issue title says server-side, but you’re both actually creating client-side (hosted) apps.
To create client-side apps, did you update to the preview 6 version of the Blazor VSIX?
I did:
dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview6.19307.2
which brought in the Visual Studio template. And I'm running latest VS Preview Update that showed up today.
Also tried dotnet new
for blazor client with the same result (as expected). As mentioned it looks like the single project, self-contained template works. It's the .NET Core hosted template that's using two separate projects that doesn't appear to be working.
Unfortunately running that command does not update the templates inside VS. You do have to install the newer VSIX.
I know it would be better if the .NET CLI and VS could keep themselves in sync better than this, but unfortunately there's still some way to go on that.
Also tried dotnet new for blazor client with the same result (as expected).
That's strange though. I'll see if I can reproduce this.
I'm afraid I've been unable to reproduce this. I have the full set of preview 6 bits, i.e.:
Microsoft.AspNetCore.Blazor.Templates
(3.0.0-preview6.19307.2)... and the "Blazor hosted" template works correctly both on the command line and from VS.
If you have any further information about how to reproduce the issue, please let us know.
replace app.UseBlazor with
app.UseClientSideBlazorFiles<Client.Startup>();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapFallbackToClientSideBlazor<Client.Startup>("index.html");
});
To create and run Blazor (ASP.NET Core hosted) App use .NET Core CLI
Please follow below steps as per Get started with Blazor | Microsoft Docs
Once you install you can create & run Blazor client-side and Blazor server-side using Visual Studio.
However if you are unable to run Blazor (ASP.NET Core hosted) app due to System.TypeLoadException then follow given steps , execute the following commands from a command shell:
Make sure you have Blazor (ASP.NET Core hosted) template installed using dotnet new -l command
If you see Blazor (ASP.NET Core hosted)/blazorhosted listed then please follow below commons to create new Blazor (ASP.NET Core hosted) app
dotnet new blazorhosted -o WebApplication1
cd WebApplication1.Server
dotnet run
you can see below details on Command Window
Hosting environment: Development
Content root path: ...\WebApplication1.Server
Now listening on: http://localhost:2470 [ Port can be different for you]
Open modern browser and navigate to localhost Url ex. http://localhost:** shown on your command window mentioned in above step 3.
@maheshkumarjadhav, followed your instructions and when navigating to http://localhost:5000 receive the following:
fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HLNJ6GDI37UA", Request id "0HLNJ6GDI37UA:00000001": An unhandled exception was thrown by the application. System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.Endpoints.EndpointHttpContextExtensions' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
@maheshkumarjadhav, followed your instructions and when navigating to http://localhost:5000 receive the following:
fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HLNJ6GDI37UA", Request id "0HLNJ6GDI37UA:00000001": An unhandled exception was thrown by the application. System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.Endpoints.EndpointHttpContextExtensions' from assembly 'Microsoft.AspNetCore.Http.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
I receive this error too, but I downloaded the SDK and am running the app in VS Code, using dotnet run
. The app builds and runs, however, whenever I access localhost I get the above error.
@maheshkumarjadhav followed your instructions... Had done all of them EXCEPT the newer extension from the marketplace once I did that the type load exception went away.
My problem was that Blazor server-side and Blazor client-side template are scaffolded with preview6 but Blazor (ASP.NET Core hosted) is scaffolded with preview5 (using Visual Studio 2019 16.1.3.
I suppose it's related to Visual Studio 2019 version that is not a preview
Closing this as this seem to be resolved already.
Most helpful comment
To create and run Blazor (ASP.NET Core hosted) App use .NET Core CLI
Please follow below steps as per Get started with Blazor | Microsoft Docs
dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview6.19307.2
Once you install you can create & run Blazor client-side and Blazor server-side using Visual Studio.
However if you are unable to run Blazor (ASP.NET Core hosted) app due to System.TypeLoadException then follow given steps , execute the following commands from a command shell:
Make sure you have Blazor (ASP.NET Core hosted) template installed using dotnet new -l command
If you see Blazor (ASP.NET Core hosted)/blazorhosted listed then please follow below commons to create new Blazor (ASP.NET Core hosted) app
you can see below details on Command Window
Open modern browser and navigate to localhost Url ex. http://localhost:** shown on your command window mentioned in above step 3.