New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to SDK 2.2.100 throws "An item with the same key has already been added. Key: .wasm" #1750

Open
michaelvolz opened this Issue Dec 5, 2018 · 13 comments

Comments

Projects
None yet
8 participants
@michaelvolz

michaelvolz commented Dec 5, 2018

I updated my Blazor project from 2.2.100-preview3-009430 to 2.2.100 release. I now get the following exception:

System.ArgumentException : An item with the same key has already been added. Key: .wasm
Stack Trace:
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Microsoft.AspNetCore.Builder.BlazorApplicationBuilderExtensions.CreateContentTypeProvider(Boolean enableDebugging)
   at Microsoft.AspNetCore.Builder.BlazorApplicationBuilderExtensions.UseBlazor(IApplicationBuilder app, BlazorOptions options)
   at Microsoft.AspNetCore.Builder.ServerSideBlazorApplicationBuilderExtensions.UseServerSideBlazor[TStartup](IApplicationBuilder builder)
   at OpenGraphTilemaker.Web.Server.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in C:\Users\flynn\Projects\OpenGraphTilemaker\src\OpenGraphTilemaker.Web.Server\Startup.cs:line 36
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.TestHost.TestServer..ctor(IWebHostBuilder builder, IFeatureCollection featureCollection)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateServer(IWebHostBuilder builder)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.EnsureServer()
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateDefaultClient(DelegatingHandler[] handlers)
   at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateClient(WebApplicationFactoryClientOptions options)
   at OpenGraphTilemaker.Web.Client.Tests.FunctionalTests.Get_EndpointsReturnSuccessAndCorrectContentType(String url) in C:\Users\flynn\Projects\OpenGraphTilemaker\tests\OpenGraphTilemaker.Web.Client.Tests\FunctionalTests.cs:line 25
--- End of stack trace from previous location where exception was thrown ---

The line
app.UseServerSideBlazor<Client.Startup>();
seems to be the reason.

Any suggestions?

@bunakbg

This comment has been minimized.

bunakbg commented Dec 5, 2018

dotnet --info:

.NET Core SDK (reflecting any global.json):
 Version:   2.1.500
 Commit:    b68b931422

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.500\

Host (useful for support):
  Version: 2.1.6
  Commit:  3f4f8eebd8

.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.403 [C:\Program Files\dotnet\sdk]
  2.1.500 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

With the Blazor server project example I didn't have any problems on windows - project compiles and runs fine. However when I try to run it in linux (same dotnet version) I have too that exception.

Currently updating to:

.NET Core SDK (reflecting any global.json):
 Version:   2.2.100
 Commit:    b9f2fa0ca8

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.100\

Host (useful for support):
  Version: 2.2.0
  Commit:  1249f08fed

.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.403 [C:\Program Files\dotnet\sdk]
  2.1.500 [C:\Program Files\dotnet\sdk]
  2.2.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

to check what's up.
In the startup.cs line 35 (I guess 36 in your case) the line there goes to public void ConfigureServices(IServiceCollection services) where it add WASM MIME type to
the collection:

           services.AddResponseCompression(options => {
                options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] {
                    MediaTypeNames.Application.Octet,
                    WasmMediaTypeNames.Application.Wasm,
                });
            });

ResponseCompressionDefaults.MimeTypes has the normal/text, normal/css etc. (don't remember them all - hardcode desktop guy here - don't know very well the "web stuff") and the .Concat exclusively adds .wasm to the collection.
Only assigning options.MimeTypes directly with ResponseCompressionDefaults.MimeTypes still works fine on windows but yet again gives error on linux with the same exception:

          services.AddResponseCompression(options => {
                options.MimeTypes = ResponseCompressionDefaults.MimeTypes; //.Concat(new[] {
                //    MediaTypeNames.Application.Octet,
                //    WasmMediaTypeNames.Application.Wasm,
                //});
            });

After the 2.2.100 update will post comments if something changes.

@michaelvolz

This comment has been minimized.

michaelvolz commented Dec 5, 2018

@bunakbg I already commented out the whole services.AddResponseCompression section but the error is still the same.

@bunakbg

This comment has been minimized.

bunakbg commented Dec 5, 2018

@michaelvolz are you getting this error on windows or linux? because after update to 2.2.100 I don't have this error on windows (still have it on linux tho...)
try this in cmd:
dotnet new blazorserverside -o blazorserver
this will create new blazorserverside type project

cd blazorserver
cd blazorserver.Server
dotnet run blazor.Server.csproj
@michaelvolz

This comment has been minimized.

michaelvolz commented Dec 5, 2018

@bunakbg My problems are on windows.

This works:

cd blazorserver
cd blazorserver.Server
dotnet run blazor.Server.csproj

But when I update

<TargetFramework>netcoreapp2.2</TargetFramework>

and

<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2" />

it throws the exception.

Additionally I added a global.json because I've already installed 3.0.100-preview-009812:

{
  "sdk": {
    "version": "2.2.100"
  }
}
@bunakbg

This comment has been minimized.

bunakbg commented Dec 5, 2018

A very, very bad workaround (if you only want to play and test with it, till this is fixed) is to build normal blazor project and manually copy contents of bin/Debug/netstandard2.0/*.* and host them to separate web server.
Bear in mind that directly opening index.html from that folder will not work as it uses CORS.
I have a project in which I am using cefSharp, ultra simple http server (only to "host" the files cause there is a fetch which doesn't works for local files) and blazor (self-contained).
If you need example - let me know, will post it here somewhere.

This doesn't fix your problem and it may be reeeally off-topic but it may help you (don't know your case).

@michaelvolz

This comment has been minimized.

michaelvolz commented Dec 5, 2018

My workaround is simpler. Just use this global.json. Done.

{
  "sdk": {
    "version": "2.2.100-preview3-009430"
  }
}

And you need of course the corresponding SDK installed 😸
Even my updates mentioned earlier work fine.

@bunakbg

This comment has been minimized.

bunakbg commented Dec 5, 2018

@michaelvolz interesting stuff ... based on this global.json is no more and it's replaced by *.csproj
Opening mine yielded some interesting stuff - I was using 2.1.500 (no matter that I choose .NET Core 2.2 upon solution creation - using Visual Studio 2017 community) and when changed to 2.2 - it did gives me error on windows too with the same exception.
Will update to latest preview to see if it's working on linux. Thanks for pointing me to the right direction.

@jcornell

This comment has been minimized.

jcornell commented Dec 5, 2018

It looks like

".wasm", "application/wasm"

was recently added to FileExtensionContentTypeProvider:
https://github.com/aspnet/AspNetCore/blob/master/src/StaticFiles/src/Microsoft.AspNetCore.StaticFiles/FileExtensionContentTypeProvider.cs
(Commit: aspnet/StaticFiles@a5fcd9d#diff-3534185c350428a9c533fe5c29596890)

The UseBlazor method calls CreateContentTypeProvider which will always fail as a result of the .wasm addition:

private static IContentTypeProvider CreateContentTypeProvider(bool enableDebugging)
    {
      FileExtensionContentTypeProvider contentTypeProvider = new FileExtensionContentTypeProvider();
      contentTypeProvider.Mappings.Add(".dll", "application/octet-stream");
      contentTypeProvider.Mappings.Add(".mem", "application/octet-stream");
      contentTypeProvider.Mappings.Add(".wasm", "application/wasm");
      if (enableDebugging)
        contentTypeProvider.Mappings.Add(".pdb", "application/octet-stream");
      return (IContentTypeProvider) contentTypeProvider;
    } 

Update: The issue has been addressed as part of this commit: aspnet/AspNetCore@5c1fbe1#diff-0cff27aae9e3ba66997ab8244a54fa57

@JulienM28

This comment has been minimized.

JulienM28 commented Dec 6, 2018

I got the exactly same issue this morning.
Rolling back to 2.1 framework is fine.

@cilerler

This comment has been minimized.

cilerler commented Dec 8, 2018

@danroth27 is there any chance to get a hotfix for this?

@robertsundstrom

This comment has been minimized.

robertsundstrom commented Dec 10, 2018

Any chance someone will make new build with the fixes that @SteveSandersonMS made? I really want a package.

aspnet/AspNetCore@5c1fbe1#diff-0cff27aae9e3ba66997ab8244a54fa57

@danroth27

This comment has been minimized.

Member

danroth27 commented Dec 10, 2018

Thanks everyone for reporting this issue! I apologize for the inconvenience.

To workaround this issue you will need to have your Blazor projects continue to target .NET Core 2.1 (netcoreapp2.1). We aren't planning to patch this issue because there is a workaround and we are currently focused on getting Razor Components into .NET Core 3.0. This issue will be fixed once we release the first public preview of Razor Components early next year.

@isaac2004

This comment has been minimized.

isaac2004 commented Dec 12, 2018

@danroth27 So to summarize, there is currently no support for Blazor on .NET Core 2.2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment