Skip to content
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" #5666

Closed
michaelvolz opened this issue Dec 5, 2018 · 26 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed

Comments

@michaelvolz
Copy link

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
Copy link

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
Copy link
Author

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

@bunakbg
Copy link

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
Copy link
Author

@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
Copy link

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
Copy link
Author

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
Copy link

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
Copy link

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: 5c1fbe1#diff-0cff27aae9e3ba66997ab8244a54fa57

@Julien-Marpault
Copy link

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

@cilerler
Copy link

cilerler commented Dec 8, 2018

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

@marinasundstrom
Copy link

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

5c1fbe1#diff-0cff27aae9e3ba66997ab8244a54fa57

@danroth27
Copy link
Member

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.

@isaacrlevin
Copy link
Contributor

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

@msauper
Copy link

msauper commented Dec 12, 2018

@jcornell I don't think that resolves the issue. The change to use AddMapping() to conditionally add definitions is all fine and good. But the problem is that the BlazorApplicationBuilderExtensions.CreateContentTypeProvider() method adds its own definition for ".wasm" AFTER the FileExtensionContentTypeProvider constructor adds a definition. The same AddMapping() logic needs to be used in CreateContentTypeProvider() or, if ".wasm" is going to be a standard entry from FileExtensionContentTypeProvider, the code can be removed from CreateContentTypeProvider.

@jcornell
Copy link

@msauper In the commit that I linked to: 5c1fbe1#diff-0cff27aae9e3ba66997ab8244a54fa57 the Additions are using the same AddMapping() logic:

private static IContentTypeProvider CreateContentTypeProvider(bool enableDebugging)
{
	var result = new FileExtensionContentTypeProvider();
	AddMapping(result, ".dll", MediaTypeNames.Application.Octet);
	AddMapping(result, ".wasm", WasmMediaTypeNames.Application.Wasm);

	if (enableDebugging)
	{
		AddMapping(result, ".pdb", MediaTypeNames.Application.Octet);
	}

	return result;
}

private static void AddMapping(FileExtensionContentTypeProvider provider, string name, string mimeType)
{
	if (!provider.Mappings.ContainsKey(name))
	{
		provider.Mappings.Add(name, mimeType);
	}
} 

Or am I misunderstanding what you're saying?

@danroth27
Copy link
Member

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

@isaac2004 That's correct. And instead of spending time patching it we are focusing our efforts on getting Razor Components working in .NET Core 3.0.

@msauper
Copy link

msauper commented Dec 12, 2018 via email

@aspnet-hello aspnet-hello transferred this issue from dotnet/blazor Dec 17, 2018
@aspnet-hello aspnet-hello added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-blazor Includes: Blazor, Razor Components labels Dec 17, 2018
@malachib
Copy link

malachib commented Dec 26, 2018

On my linux machines this pinning down works. On my mac however I get the same wasm error as before. Using a global.json like this:

{
  "sdk": {
    "version": "2.1.400"
  }
}

And using 2.1.5 LTS which comes with 2.1.403 SDK

On both mac and linux, dotnet --version reports 2.1.403

NOTE: Mac also has 2.2 on it, while some of my linux machines don't

@mkArtakMSFT
Copy link
Member

@SteveSandersonMS, if this is already fixed, please resolve.

@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Jan 15, 2019
@mkArtakMSFT mkArtakMSFT added this to the 3.0.0-preview2 milestone Jan 15, 2019
@SteveSandersonMS
Copy link
Member

Fixing in #6731

@SteveSandersonMS
Copy link
Member

Actually it turns out it was already fixed (by conditionally adding the mapping), but the updated fix in #6731 is better because it's simpler.

@SteveSandersonMS SteveSandersonMS added the Done This issue has been fixed label Jan 16, 2019
@ctrl-alt-d
Copy link

I have the issue on 3.0.100-preview-010184 :

$ dotnet run --project Aliga3.XXX

C:\Program Files\dotnet\sdk\3.0.100-preview-010184\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(154,5): warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically. Otherwise, the PackageReference should be replaced with a FrameworkReference. [C:\Users\XXX\projectes\XXX\XXX.BlazorRestServer\XXX.BlazorRestServer.csproj]

Application startup exception: System.ArgumentException: An item with the same key has already been added. Key: .wasm

( I included warning just to show the version )

@SteveSandersonMS
Copy link
Member

@ctrl-alt-d Looks like your app must still be using the earlier packages (Blazor 0.7.0?). It's only fixed in the newer bits we haven't released yet.

@sheryever
Copy link

@danroth27 after installing dotnet core version 3.0.100 on Windows 10 and Windows 2012 R2 (Hosting machine) a component written in dotnet standard 2 the dictionary is throwing "An item with the same key..." exception with a little strange behavior. They key i am adding is string while dictionary is showing random integer keys every time in the exception. like: "An item with the same key has already been added. Key: 7166148"

@danroth27
Copy link
Member

@sheryever Could you please open a new issue with the full details on how to reproduce the problem you are seeing?

@sheryever
Copy link

@danroth27 our issue resolved, the dictionary was a static variable, we fixed it by using lock statement.

The interesting thing that we noticed with aspnet core is, the controller action was not async and neither running any thread but still it looks that more than one thread was accessing the dictionary at once on multiple calls from browser :)

@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Projects
None yet
Development

No branches or pull requests