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 (https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1030) and NSwag (https://github.com/RSuter/NSwag/issues/1961#issuecomment-470288203).
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=220.127.116.11, 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)
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
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.