Skip to content

MVC apps no longer work with PublishTrimmed #49360

@eerhardt

Description

@eerhardt

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Using an MVC app with PublishTrimmed no longer works. The same app worked in .NET 7.

This appears to be caused by the JsonSerializerIsReflectionEnabledByDefault changes. See dotnet/runtime#84378.

FYI @eiriktsarpalis

Expected Behavior

The app should work.

Steps To Reproduce

  1. dotnet new mvc
  2. Add <PublishTrimmed>true</PublishTrimmed> to the csproj
  3. dotnet run

Exceptions (if any)

Unhandled exception. System.InvalidOperationException: JsonSerializerOptions instance must specify a TypeInfoResolver setting before being marked as read-only.
   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerOptionsNoTypeInfoResolverSpecified()
   at System.Text.Json.JsonSerializerOptions.MakeReadOnly()
   at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter..ctor(JsonSerializerOptions jsonSerializerOptions)
   at Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.CreateFormatter(JsonOptions jsonOptions)
   at Microsoft.AspNetCore.Mvc.MvcCoreMvcOptionsSetup.Configure(MvcOptions options)
   at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
   at Microsoft.Extensions.Options.UnnamedOptionsManager`1.get_Value()
   at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.<>c.<AddMvcCoreServices>b__5_0(IServiceProvider s)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)

.NET Version

8.0.100-preview.7.23360.2

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions