Net core 2.2 to .Net 8.0 project. I am getting the following error. I am using the Visual Studio 2022 Upgrade Assistant.
(Same problem if I update to version 3.2)
Application Startup Exception: System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Mvc.MvcJsonOptions' from assembly 'Microsoft.AspNetCore.Mvc.Formatters.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken =adb9793829ddae60'.
in System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
at System.Reflection.RuntimeConstructorInfo.<get_Signature>g__LazyCreateSignature|21_0()
in System.Reflection.RuntimeConstructorInfo.GetParametersNoCopy()
in System.Reflection.RuntimeConstructorInfo.GetParameters()
at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, instance type, object parameters[])
at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.ReflectionMiddlewareBinder.CreateMiddleware (RequestDelegate below)
at Microsoft.AspNetCore.Builder.ApplicationBuilder.Build ()
in Microsoft.AspNetCore.Hosting .WebHost.BuildApplication()
I have updated to the Microsoft.AspNetCore.Mvc.NewtonsoftJson nuget package - 8.0.2
I also tried adding the following code in startup.cs services.AddMvc(options => options.EnableEndpointRouting = false)
.AddNewtonsoftJson();
and
services.AddControllers()
.AddNewtonsoftJson();
I'm not sure why it's still looking for the old nuget package and the Microsoft.AspNetCore.Mvc.MvcJsonOptions assembly from version 2.2.
When I tried to find the old Microsoft.AspNetCore.Mvc.MvcJsonOptions assembly in the project folder, I found it in the test project in the bin\Debug\net8.0\refs folder. I tried to remove it but it is adding it again in the build.
I have updated to the Microsoft.AspNetCore.Mvc.NewtonsoftJson nuget package - 8.0.2
I also tried adding the following code in startup.cs services.AddMvc(options => options.EnableEndpointRouting = false)
.AddNewtonsoftJson();
and
services.AddControllers()
.AddNewtonsoftJson();
I'm not sure why it's still looking for the old nuget package and the Microsoft.AspNetCore.Mvc.MvcJsonOptions assembly from version 2.2.