I updated my Blazor project from 2.2.100-preview3-009430
to 2.2.100
release. I now get the following exception:
C#
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?
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.
@bunakbg I already commented out the whole services.AddResponseCompression
section but the error is still the same.
@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
@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"
}
}
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).
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.
@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.
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: https://github.com/aspnet/StaticFiles/commit/a5fcd9dd8724eb71f0642340f68aeb85b0473374#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: https://github.com/aspnet/AspNetCore/commit/5c1fbe1af7b8b6a36289de0d175608a16a1e284c#diff-0cff27aae9e3ba66997ab8244a54fa57
I got the exactly same issue this morning.
Rolling back to 2.1 framework is fine.
@danroth27 is there any chance to get a hotfix for this?
Any chance someone will make new build with the fixes that @SteveSandersonMS made? I really want a package.
aspnet/AspNetCore@5c1fbe1#diff-0cff27aae9e3ba66997ab8244a54fa57
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.
@danroth27 So to summarize, there is currently no support for Blazor on .NET Core 2.2?
@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.
@msauper In the commit that I linked to: https://github.com/aspnet/AspNetCore/commit/5c1fbe1af7b8b6a36289de0d175608a16a1e284c#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 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.
John,
You’re right. I missed the change to CreateContentTypeProvider() as I read through the change set.
Best regards,
Metro.
Sent from my iPad
On Dec 12, 2018, at 5:56 PM, John Cornell <[email protected]notifications@github.com> wrote:
@msauperhttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmsauper&data=02%7C01%7C%7Ceab718084024429c8ceb08d660850427%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636802521742252794&sdata=iKxrlbXdEk%2BL%2B0QhD4wP6f%2F6R4%2FUo3opi5ugsxRiR%2FA%3D&reserved=0 In the commit that I linked to: aspnet/AspNetCore@5c1fbe1#diff-0cff27aae9e3ba66997ab8244a54fa57https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Faspnet%2FAspNetCore%2Fcommit%2F5c1fbe1af7b8b6a36289de0d175608a16a1e284c%23diff-0cff27aae9e3ba66997ab8244a54fa57&data=02%7C01%7C%7Ceab718084024429c8ceb08d660850427%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636802521742252794&sdata=gCBzuKDR3mJYxTBO105huB%2Fo%2B7fS9wb%2FZ2fVtzR0o2c%3D&reserved=0 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?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Faspnet%2FBlazor%2Fissues%2F1750%23issuecomment-446775578&data=02%7C01%7C%7Ceab718084024429c8ceb08d660850427%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636802521742252794&sdata=OQ5xuVjNUfbwIpgS719ciq%2BToVkXJOokxAsrW%2BiXkO4%3D&reserved=0, or mute the threadhttps://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FADottvAYL8GcZU8KK0-HhyDo2V9GhJaOks5u4YmMgaJpZM4ZCVjx&data=02%7C01%7C%7Ceab718084024429c8ceb08d660850427%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636802521742252794&sdata=pp3L2EbjaKa3lu5MG%2FsLKHKK8yBqEXdZj801NQuBCGY%3D&reserved=0.
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
@SteveSandersonMS, if this is already fixed, please resolve.
Fixing in #6731
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.
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 )
@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.
@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"
@sheryever Could you please open a new issue with the full details on how to reproduce the problem you are seeing?
@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 :)
Most helpful comment
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.