0

when I am running my application then it's showing me error like Could not load type 'Could not load type 'Microsoft.AspNetCore.Mvc.MvcJsonOptions' from assembly 'Microsoft.AspNetCore.Mvc.Formatters.Json, Version=3.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60.

My csproj file contains code like below :

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>Insurance_Customer_Portal_API</RootNamespace>
    <AddRazorSupportForMvc>true</AddRazorSupportForMvc>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.1.1" />
    <PackageReference Include="SwashBuckle.AspNetCore.MicrosoftExtensions" Version="0.5.0" />
    <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0" />
  </ItemGroup>

</Project>

Is there any things which I need to change in code ?

1 Answer 1

2

You have some dependencies in your project that are not required anymore, which are causing a mismatch of actually used DLLs that end up in the build-output.

  1. When your project uses Microsoft.NET.Sdk.Web and >= netcoreapp3.0, a reference to Microsoft.AspNetCore.App is not required so that line can be safely removed.
  2. Microsoft.AspNetCore.Cors is also part of the framework now so you don't need an explicit reference.
  3. Last but not least, add a NuGet reference to Microsoft.AspNetCore.Mvc.NewtonsoftJson which can be found here.
Sign up to request clarification or add additional context in comments.

4 Comments

So should I add <FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.1.0" /> in csproj file ?
No, you have to remove it, as stated before.
I am using 1. Microsoft.AspNetCore.Mvc.NewtonsoftJson, 2. Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer, 3. SwashBuckle.AspNetCore.MicrosoftExtensions, 4. Swashbuckle.AspNetCore.SwaggerUI. But still it's showing me same error. Still am I wrong on any page ?
I just saw that SwashBuckle.AspNetCore.MicrosoftExtensions has very old dependencies and has not been updated since 2018. Can you try removing the dependency?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.