-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore MvcJsonOptions to ASP.NET Core 3.0 as a type forward? #8254
Comments
Thanks for contacting us, @martincostello. |
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. |
I'm going to do a quick attempt at something for this now and submit a draft PR for discussion. |
Restore the MvcJsonOptions type as a type-forwarded proxy for backwards compatibility with libraries such as NSwag and Swashbuckle.AspNetCore. Relates to dotnet#8254.
See #8437. |
Thanks for the PR @martincostello. I basically came up with the sort of solution to what your PR sent. Here's a couple of my notes from it:
We have a meeting planned to talk about this soon. I'll update the issue once we've figured out how to proceed with this. |
Awesome - thanks @pranavkm! |
I think we need to add a new target framework (.NET Core 3) in NSwag anyway which will reference ASP.NET Core 3.0 (which I really don't like as it means you cannot use ASP.NET Core 2.2 on .NET Core 3). With this new target framework we can easily fix the renaming issue... But I'd still like to see the type forward (at least in the previews) as it means that we don't have to directly support the preview version in NSwag (yet) :-) |
We had a meeting to talk about this. This issue with the
While it's not super common, requiring the package reference to be present just to be able to iterate through all the assemblies in the App seems really problematic. @davidfowl is going to figure out if we can get some support from the CLR to solve this. In the meanwhile, we'll work with our Swagger \ Open API partners to adopt the 3.0 changes. Like @RSuter pointed out, it's might relatively straightforward since we could pivot on the TFM. |
Running into the same problem. As a user, is there a workaround for me? Or do I need to wait for a fix in preview4? |
With preview3 there isn't currently a workaround other than using locally compiled forks of the affected assemblies which are changed to use 3.0 preview 3. Otherwise you need to wait for preview4, roll back to preview 2, or wait for libraries to publish versions that are compiled against preview3. |
Thanks for contacting us. |
NSwag now uses reflection to use the new type when available... should be fixed there. |
I'm actually still running into this (or a similar) problem with preview 4. The callstack is slightly different though. Is this a different problem? How can I find out which assembly causes the troubling reference? What can I do about it? Csproj: https://github.com/Dynatrace/superdump/blob/netcore3/src/SuperDumpService/SuperDumpService.csproj Exception:
|
Are you using a version of NSwag or Swashbuckle.AspNetCore that is compatible with preview 3/4? |
Oh, thanks for that question. I checked and found out I was referencing only
instead. Now the error is resolved. Thank you! |
Seems to be that Ocelot have the same problem.
|
@jsantanders - thanks for bringing this up. I"m following up on the Ocelot repo. |
I'm having the similar issue after upgrading to .net core 3.0 Could not load type 'Microsoft.Extensions.DependencyInjection.MvcJsonMvcCoreBuilderExtensions' from assembly 'Microsoft.AspNetCore.Mvc.Formatters.Json, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.' Why is this issue closed? This issue is not fixed at all. Any suggestions? Thank you very much |
I got the same issue as you because I just tried to upgrade my app to v3.0 this morning. |
I upgraded to dotnet core today, and run into the same problem. I did a little more searching and found this: https://stackoverflow.com/a/58084490 The answer talks about installing the latest Swagger package, which at the time of writing this is rc4. I installed RC4 of Swashbuckle |
Has this issue been resolved? I am trying to upgrade my Asp .Net Core 2.2 MVC Web API project from 2.2 to 3.0 but I am facing an issue. I am using Swashbuckle AspNetCore for my Swagger UI API documentation. But on upgrade to 3.0 I get this error - |
The issue as described in the title was resolved. You're experiencing a wider issue caused by the breaking changes made in ASP.NET Core 3.0 for consuming Newtonsoft.Json. Only 5.0.0-rc2 and later of |
The issue is still there if you are using Ocelot as apigateway ===================================
|
Swashbuckle 5.0.0-rc4 worked for me. In vs - make sure you tick the 'include prerelease' right next to the search box of the package manager. |
We are aware that this is a breaking change for libraries and individual libraries have to reconcile this either by using reflection or by cross-compiling (https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#migrate-libraries-via-multi-targeting). The most recent releases of Closing this as resolved as there's nothing further to do here. If you think there's further work for us to do, please file a new issue. |
Problem
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 (domaindrivendev/Swashbuckle.AspNetCore#1030) and NSwag (RicoSuter/NSwag#1961 (comment)).
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 accessJsonSerializerSettings
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.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 theMicrosoft.AspNetCore.Mvc.Formatters.Json
assembly toMicrosoft.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.The text was updated successfully, but these errors were encountered: