TypeLoadException: Could not load type ‘Microsoft.AspNetCore.Mvc.MvcJsonOptions’ from assembly ‘Microsoft.AspNetCore.Mvc.Formatters.Json

Issue Description

While adding Swagger to .NET Core 3.0 gives below error,

TypeLoadException: Could not load type ‘Microsoft.AspNetCore.Mvc.MvcJsonOptions’ from assembly ‘Microsoft.AspNetCore.Mvc.Formatters.Json

Resolution:

The issue I found to be due to encompatiblity of existing swagger/swashbuckle packges with latest .NET Core i.e 3.0.

Below is how I was able to fix the issue.

  • Please uninstall any old version of Swagger / Swashbuckle packages.
  • Please install below Swashbuckle Nuget package using package manager console,

PM> Install-Package Swashbuckle.AspNetCore -Version 5.0.0

[Note: Please use latest available version]

Please see step by step on enabling Swagger(Open API) to.NET Core 3.0 web API.

Above package will install everything else required for swagger like,

  • Swashbuckle.AspNetCore.SwaggerUI 5.0.0
  • Swashbuckle.AspNetCore.Swagger 5.0.0
  • Swashbuckle.AspNetCore.SwaggerGen 5.0.0

That’s all, You are all set with a fix, now you can run and test your swagger documentation.

Please make a note of a few breaking changes from .NET Core 2.2 to 3.0 in Swagger. I have detailed them in the article Swagger API Documentation in .NET Core 3.0.

Other useful References:

Did the above steps resolve your issue?

Please sound off in the comments below!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



4 thoughts on “Resolved: TypeLoadException: Could not load type ‘Microsoft.AspNetCore.Mvc.MvcJsonOptions’ swagger error

    1. Hello Iara – Thank you for reading and providing your feedback. The current version available is RC only and cover lot of improvements including breaking changes. You can try using Swashbuckle.AspNetCore.SwaggerUI 5.0.0-rc4 which is latest available released recently.

Leave a Reply

Your email address will not be published. Required fields are marked *