Ask questionsRestore MvcJsonOptions to ASP.NET Core 3.0 as a type forward?


As originally brought up in #7220, the removal of Newtonsoft.Json as a core dependency is causing breaking application changes for applications exposing Swagger/Open API documentation using existing popular libraries such as Swashbuckle.AspNetCore ( and NSwag (

These projects (and possibly others) have been built to rely on the MvcJsonOptions type present in earlier versions of ASP.NET Core and its presence in the DI system to access JsonSerializerSettings for JSON serialization purposes.

These errors manifest as TypeLoadException in ASP.NET Core 3.0 preview 3, and cannot easily be resolved without binary breaking changes to such libraries.

System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Mvc.MvcJsonOptions' from assembly 'Microsoft.AspNetCore.Mvc.Formatters.Json, Version=, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Signature..ctor(IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Reflection.RuntimeConstructorInfo.get_Signature()
   at System.Reflection.RuntimeConstructorInfo.GetParametersNoCopy()
   at System.Reflection.RuntimeConstructorInfo.GetParameters()
   at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher..ctor(ConstructorInfo constructor)
   at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass4_0.<UseMiddleware>b__0(RequestDelegate next)
   at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
   at Microsoft.AspNetCore.Hosting.Internal.GenericWebHostService.StartAsync(CancellationToken cancellationToken)

Suggested Solution

To provide an improved migration path for such applications where the presence of Newtonsoft.Json as a dependency is not an issue, could the MvcJsonOptions class be restored as type-forwarded from the Microsoft.AspNetCore.Mvc.Formatters.Json assembly to Microsoft.AspNetCore.Mvc.NewtonsoftJson?

The forwarded type could be marked as [Obsolete] to discourage use and removed in ASP.NET Core 4.0, while providing a "crutch" of sort to prevent blockers and/or delays to adoption of ASP.NET Core 3.0 in existing ASP.NET Core 2.x applications due to the extensive usage of Newtonsoft.Json in non-Microsoft libraries.


Answer questions JohnGalt1717

This is a blocker. It basically makes any API layer unusable in .NET Core 3 Preview 3 because they'll all depend on this working if they have swagger documention which is essentially all of them.


Related questions

HTTP Error 500.31 - ANCM Failed to Find Native Dependencies hot 523
ERR_HTTP2_INADEQUATE_TRANSPORT_SECURITY when clean webapi template hot 505
The SPA default page middleware could not return the default page '/index.html' in production application hot 310
Issue with BuildServiceProvider() in ConfigureServices() hot 285
HTTP Error 500.30 - ANCM In-Process Start Failure hot 282
HTTP Error 500.30 - ANCM In-Process Start Failure hot 249
Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvc', please set 'MvcOptions.EnableEndpointRounting = false' inside 'ConfigureServices'. hot 241
Calling Request.EnableRewind throw on 3.0.0-preview7 hot 219
ERR_HTTP2_INADEQUATE_TRANSPORT_SECURITY when clean webapi template hot 206
DataProtection - CryptographicException when using EntityFramework as Key Storage Provider hot 181
error CS1503: Argument 2: cannot convert from 'method group' to 'EventCallback' hot 160
Error: Server returned handshake error: Handshake was canceled. hot 152
Blazor - rzc generate exited with code 1. DotNet Core 3.0.100-preview8-013656 hot 150
IIS in-process hosting incorrectly throws ConnectionResetException for HTTP POST hot 149
NullReferenceException in IISHttpContext hot 135
Github User Rank List