runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Could not load type 'System.Text.Json.JsonDocumentOptions' from assembly 'System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

Open pc-tradelab opened this issue 7 years ago • 8 comments

Hi I am having this issue when trying to migrate my identityserver4 server to dotnetcore3.0 :

TypeLoadException: Could not load type 'System.Text.Json.JsonDocumentOptions' from assembly 'System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Microsoft.AspNetCore.Authentication.Google.GoogleHandler.CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens) System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<TStateMachine>(ref TStateMachine stateMachine) System.Runtime.CompilerServices.AsyncTaskMethodBuilder<TResult>.Start<TStateMachine>(ref TStateMachine stateMachine) Microsoft.AspNetCore.Authentication.Google.GoogleHandler.CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens) Microsoft.AspNetCore.Authentication.OAuth.OAuthHandler<TOptions>.HandleRemoteAuthenticateAsync() Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()

The version I am using : ` Host (useful for support): Version: 3.0.0-preview-27324-5 Commit: 63a01b08e5

.NET Core runtimes installed: Microsoft.AspNetCore.App 3.0.0-preview-19075-0444 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.0.0-preview-27324-5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

`

Thanks !

pc-tradelab avatar Oct 07 '19 10:10 pc-tradelab

Better to use released .net core version then the preview one

KamranShahid avatar Oct 07 '19 17:10 KamranShahid

These types of issues occur whenever you have mismatched/out-dated bits. Can you please retry with .NET Core 3.0 GA (including 3.0 AspNetCore)? https://dotnet.microsoft.com/download/dotnet-core/3.0

ahsonkhan avatar Oct 08 '19 00:10 ahsonkhan

ok thanks i was using: microsoft/dotnet:3.0-aspnetcore-runtime which seems outdated. I am using now the official mcr.microsoft.com/dotnet/core/aspnet:3.0

pc-tradelab avatar Oct 08 '19 12:10 pc-tradelab

I am still getting this error even when I am 100% convinced I am only building with the GA DotnetCore 3.0

dotnet --list-sdks 2.1.302 [/usr/local/share/dotnet/sdk] 2.1.403 [/usr/local/share/dotnet/sdk] 2.1.505 [/usr/local/share/dotnet/sdk] 2.2.104 [/usr/local/share/dotnet/sdk] 2.2.300 [/usr/local/share/dotnet/sdk] 3.0.100 [/usr/local/share/dotnet/sdk]

dotnet --list-runtimes Microsoft.AspNetCore.All 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

But I still get this

Could not load type 'System.Text.Json.Serialization.JsonSerializerOptions' from assembly 'System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

I am referencing

PackageReference Include="Microsoft.AspNetCore.ProtectedBrowserStorage" Version="0.1.0-alpha.19406.1"

In my startup.cs public void ConfigureServices(IServiceCollection services) { services.AddProtectedBrowserStorage(); ...... other stuff }

In my Page

Title = await ProtectedSessionStore.GetAsync(SessionKeyName);

That's when I get the error :(

Mark.

markgr avatar Oct 10 '19 23:10 markgr

@markgr - can you please share a simplified repro project where you are seeing this issue? That would help me root cause what's going on here. Thanks.

ahsonkhan avatar Oct 11 '19 00:10 ahsonkhan

I'll throw one together later - what's the chances that one works :)

markgr avatar Oct 11 '19 02:10 markgr

Ok hit

https://github.com/markgr/BlazorJson.git

Just dotnet restore, dotnet build, dotnet run open localhost:5000 - i think it redirects to the https - I literally created it out of the box.

Hit the Home page and click the 'Test Storage' button - check the console and you will see the error

Could not load type 'System.Text.Json.Serialization.JsonSerializerOptions' from assembly 'System.Text.Json, Version=4.0.0.0

All I did was

1.) dotnet add package Microsoft.AspNetCore.ProtectedBrowserStorage --version 0.1.0-alpha.19406.1 2.) Added services.AddProtectedBrowserStorage(); in startup.cs 3.) Added a button and then hooked up the following code

sync Task TestStorage() { try { await ProtectedSessionStore.SetAsync("Name", "Mark"); } catch(Exception ex) { Console.WriteLine(ex.Message); } }

markgr avatar Oct 11 '19 03:10 markgr

I took a look at this repro and found the cause. The references are coming from Microsoft.AspNetCore.ProtectedBrowserStorage which is very old and was built against a pre-release version of System.Text.Json prior to some type renames. I did find that the newer version of the package (0.1.0-alpha.19521.1) avoids these TypeLoadExceptions. Given this package was never shipped stable, I'm guessing there is a different place for you to get this API. https://www.nuget.org/packages/Microsoft.AspNetCore.ProtectedBrowserStorage

It looks to me like you should probably be getting those types from https://github.com/dotnet/aspnetcore/blob/ed5034eb8ecde1e0151f70da43203affd1375c46/src/Components/Web.Extensions/src/Microsoft.AspNetCore.Components.Web.Extensions.csproj instead. cc @mkArtakMSFT @MackinnonBuck

ericstj avatar Aug 06 '20 21:08 ericstj