aspnetcore: Blazor server side template in VS 2019 throws System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Http.Endpoints.EndpointHttpContextExtensions'

Describe the bug

A TypeLoadException is thrown when attempting to start a Blazor server side web application that is created using the default VS 2019 templates.

To Reproduce

  1. Steps to reproduce the behavior:
  2. Enable “Use previews of .NET Core SDK” in VS 2019 options (Environment > Preview Features)
  3. Using the New Project dialog, create a server side Blazor web application
  4. Hit F5 to start the application
  5. See error in browser

Expected behavior

The example web application should start without any exceptions being thrown

Additional context

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.<Attach>b__0(HttpContext context, Func1 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, Func1 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 17.568ms 500 text/plain

dotnet --info

.NET Core SDK (reflecting any global.json): Version: 3.0.100-preview6-012264 Commit: be3f0c1a03

Runtime Environment: OS Name: Windows OS Version: 10.0.18362 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\

Host (useful for support): Version: 3.0.0-preview6-27804-01 Commit: fdf81c6faf

.NET Core SDKs installed: 1.1.13 [C:\Program Files\dotnet\sdk] 1.1.14 [C:\Program Files\dotnet\sdk] 2.1.602 [C:\Program Files\dotnet\sdk] 2.1.604 [C:\Program Files\dotnet\sdk] 2.1.700 [C:\Program Files\dotnet\sdk] 2.2.202 [C:\Program Files\dotnet\sdk] 2.2.204 [C:\Program Files\dotnet\sdk] 2.2.300 [C:\Program Files\dotnet\sdk] 3.0.100-preview6-012264 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-preview6.19307.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 15 (6 by maintainers)

Most upvoted comments

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

  1. Install the latest .NET Core 3.0 Preview SDK release.
  2. Install the Blazor templates by running the following command in a command shell: dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview6.19307.2
  3. Install the latest Blazor extension from the Visual Studio Marketplace. This step makes Blazor templates available to Visual Studio.

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:

  1. Make sure you have Blazor (ASP.NET Core hosted) template installed using dotnet new -l command

  2. 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
    
  3. 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]
    
  4. Open modern browser and navigate to localhost Url ex. http://localhost😗*** shown on your command window mentioned in above step 3.

Same for me with new project…

  • Installed latest SDK of Preview 6
  • Installed the Blazor Template per instruction from Blazor.net

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.

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

test

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?

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

@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.

replace app.UseBlazor with

app.UseClientSideBlazorFiles<Client.Startup>();
app.UseRouting();
 app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
                endpoints.MapFallbackToClientSideBlazor<Client.Startup>("index.html");
            });

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.