You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple self-contained trimmed web app crashes with the following error on both Win and Linux using both dotnet 8 and 9-preview.
System.NotSupportedException: JsonTypeInfo metadata fortype'WeatherForecast[]' was not provided by TypeInfoResolver of type'[]'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.
System.NotSupportedException: JsonTypeInfo metadata fortype'WeatherForecast[]' was not provided by TypeInfoResolver of type'[]'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_NoMetadataForType(Type, IJsonTypeInfoResolver)
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type, Boolean , Nullable`1 , Boolean , Boolean ) at System.Text.Json.JsonSerializerOptions.GetTypeInfo(Type) at Microsoft.AspNetCore.Http.Generated.<GeneratedRouteBuilderExtensions_g>F96C975B3E0B9F18FACA799FFF0501F8E65F4725A296BAA3D4A322AEDFF0D73FE__GeneratedRouteBuilderExtensionsCore.<>c.<MapGet0>b__2_1(Delegate del, RequestDelegateFactoryOptions options, RequestDelegateMetadataResult inferredMetadataResult) in /src/obj/Release/net8.0/linux-musl-x64/Microsoft.AspNetCore.Http.RequestDelegateGenerator/Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator/GeneratedRouteBuilderExtensions.g.cs:line 88 at Microsoft.AspNetCore.Routing.RouteEndpointDataSource.CreateRouteEndpointBuilder(RouteEntry, RoutePattern , IReadOnlyList`1 , IReadOnlyList`1 ) at Microsoft.AspNetCore.Routing.RouteEndpointDataSource.get_Endpoints() at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.CreateEndpointsUnsynchronized() at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.EnsureEndpointsInitialized() at Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.get_Endpoints() at Microsoft.AspNetCore.Routing.DataSourceDependentCache`1.Initialize() at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& , Boolean&, Object& , Func`1) at System.Threading.LazyInitializer.EnsureInitialized[T](T& , Boolean&, Object& , Func`1) at Microsoft.AspNetCore.Routing.DataSourceDependentCache`1.EnsureInitialized() at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher..ctor(EndpointDataSource, Lifetime, Func`1) at Microsoft.AspNetCore.Routing.Matching.DfaMatcherFactory.CreateMatcher(EndpointDataSource) at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.InitializeCoreAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatcher|10_0(EndpointRoutingMiddleware, HttpContext, Task`1) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1)
.NET Version
8.0.205
Anything else?
No response
The text was updated successfully, but these errors were encountered:
iSeiryu
changed the title
PublishTrimmed causes a runtime error
PublishTrimmed causes a runtime error related to source generation
May 18, 2024
Is there an existing issue for this?
Describe the bug
A simple self-contained trimmed web app crashes with the following error on both Win and Linux using both dotnet 8 and 9-preview.
Removing
/p:PublishTrimmed=true
from thepublish
command works as expected.I'm not sure if it's a bug or an expected behavior that is not properly documented. I found docs like this one https://learn.microsoft.com/en-us/dotnet/core/compatibility/serialization/7.0/reflection-fallback but
Expected Behavior
http://localhost:5000/weatherforecast should return a valid JSON response.
Steps To Reproduce
On Windows
Via Docker
Removing
/p:PublishTrimmed=true
works as expected.Instead of creating a new project this sample project can be used.
Exceptions (if any)
.NET Version
8.0.205
Anything else?
No response
The text was updated successfully, but these errors were encountered: