Closed cesare-marasco closed 11 months ago
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis See info in area-owners.md if you want to be subscribed.
Author: | cesare-marasco |
---|---|
Assignees: | - |
Labels: | `area-System.Text.Json`, `untriaged` |
Milestone: | - |
Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.
Author: | cesare-marasco |
---|---|
Assignees: | - |
Labels: | `arch-wasm`, `area-System.Text.Json`, `untriaged` |
Milestone: | - |
This looks like a System.Text.Json + Trimming issue. Since I don't know the code in step:
The application start correctly but when i try to log in using BE api I receive following error
I assume that you're doing a HTTP request and deserializing the JSON response. When using trimming, you should use a source generated JSON Context, docs can be found here: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation
Duplicate of https://github.com/dotnet/runtime/issues/74141 and https://github.com/dotnet/runtime/issues/81709. Using the source generator is advised when using trimmed applications. You could always try to work around the specific issue using the DynamicDependencyAttribtue
(example: https://github.com/passwordless-lib/fido2-net-lib/commit/1fbfb25cb9f53a8795ab952698dcc6493df1add3) but it's likely you'll face other reliability issues.
But, Why the same code works perfectly using the previous dotNet7 ? The code is exactly the same .. to be honest everything it's as previous .. was change only SDK in the project, in the docker file of the CI pipeline..that's all... I assume that something it's changed in the json deser/ser process
I assume because the default TrimMode has been changed in .NET 8. This is documented here: https://learn.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/8.0/trimmode-full
Correct, it's not the serializer per se that has changed here, rather serialization is failing because the trimmer has removed essential information from the IL required to drive reflection-based serialization.
Hi All, @steveisok @SamMonoRT
Yesterday i migrated my Blazor Wasm Application (That consume a BE Api using JWT Auth) from dotNet7 to dotNet8 following the Microsoft official guide.
https://learn.microsoft.com/en-us/aspnet/core/migration/70-80?view=aspnetcore-8.0&tabs=visual-studio#update-the-net-sdk-version-in-globaljson
and using the suggested steps:
Update a Blazor WebAssembly app
Follow the guidance in the first three sections of this article:
1- Update the .NET SDK version in global.json 2 - Update the target framework 3 - Update package references
The migrated application works perfectly locally with visual studio in debug mode. Publish and deploy goes well. The application start correctly but when i try to log in using BE api I receive following error
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: ConstructorContainsNullParameterNames, System.Collections.Generic.KeyValuePair
2[System.Int32,System.String] System.NotSupportedException: ConstructorContainsNullParameterNames, System.Collections.Generic.KeyValuePair2[System.Int32,System.String] at System.Text.Json.ThrowHelper.ThrowNotSupportedException_ConstructorContainsNullParameterNames(Type ) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.PopulateParameterInfoValues(JsonTypeInfo ) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateTypeInfoCore(Type , JsonConverter , JsonSerializerOptions ) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateJsonTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions ) at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type ) at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context) --- End of stack trace from previous location --- at System.Text.Json.JsonSerializerOptions.CachingContext.CacheEntry.GetResult() at System.Text.Json.JsonSerializerOptions.CachingContext.GetOrAddTypeInfo(Type , Boolean ) at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Nullable
1 , Boolean , Boolean ) at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.1 , Boolean , Boolean ) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0() at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured() at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Nullable
1 , Boolean , Boolean ) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()`This error occur for any kind of compilation
RunAOTCompilation -> True or False
Previously my application was published using AOT compilation enabled, working perfectly.
The application is built and deployed using a CI/CD Azure DevOps Pipeline that produce a docker image for Azure Container Registry and deployed as Azure Container Instance.
This is a frustrating and blocking problem. I hope to receive support ASAP.
I put some configs:
Blazor Wasm Project `