Working in Visual Studio 2019, running the project in IisEpxress
I am trying to update all the projects in a solution from .NET Core 2.2 to 3.1. I have changed the versions and updated the NuGet packages of for example EntityFrameworkCore (this perticular one to 3.1.5).
In short the problem is that when I run my updated ASP.NET Core Web API project I get this error:
TypeLoadException: Could not load type 'WE.GPR.Connections.Common.DomainEntity' from assembly 'WE.GPR.Connections.Common, Version=1.0.22.0, Culture=neutral, PublicKeyToken=null'. Unknown location
The weird thing is that the model 'DomainEntity' is in the 'WE.GPR.Connections.Common.Models.DomainEntity' namespace. So it is looking in the wrong location. But when I build my solution, I get no errors.
The version of this solution that ran .NET Core 2.2 did not have this problem.
I did the same update process to another solution which uses the same project 'WE.GPR.Connections.Common'. That went fine, nothing like these errors.
It is a bit of a complex solution with submodules and custom NuGet packages from our own feed combined like so:
Root
- Project 1
- Custom NuGet package*
- Project 2
- Ref to Submodule project 3
Submodules
- Submodule project 3
*this nuget package project also has the same project 3 as a submodule
So my first assumption was that that NuGet package was messing things up, as this was the only thing different from my other solution that I am able to successfully update to 3.1 (this last mentioned solution was actually the solution that produced this NuGet package).
So I made the Submodule into another NuGet package, but the problem remains.
I also removed the entire folder with the solution from my local system and cloned it again.
I even started a fresh update from the master branch and did all the updating again, but the problem remains.
When I do a search for the 'WE.GPR.Connections.Common' I cannot find it anywhere in the solution, apart from the usage with the .Model or other namespaces behind it.
I have spend several days now on this very annoying problem.
Do you have any ideas on how to approach this next, because I have ran out of ideas myself.
Update
Yesterday I pushed the code to Azure DevOps and the build ran into the same problems as me locally, so it is definitely not something with my machine.
Here is the full error message:
Standard Output Messages:
Application startup exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'WE.GPR.Connections.Common.DomainEntity' from assembly 'WE.GPR.Connections.Common, Version=1.0.22.0, Culture=neutral, PublicKeyToken=null'.
Could not load type 'WE.GPR.Connections.Common.DomainEntity' from assembly 'WE.GPR.Connections.Common, Version=1.0.22.0, Culture=neutral, PublicKeyToken=null'.
Could not load type 'WE.GPR.Connections.Common.BaseDto' from assembly 'WE.GPR.Connections.Common, Version=1.0.22.0, Culture=neutral, PublicKeyToken=null'.
Could not load type 'WE.GPR.Connections.Common.BaseDto' from assembly 'WE.GPR.Connections.Common, Version=1.0.22.0, Culture=neutral, PublicKeyToken=null'.
Could not load type 'WE.GPR.Connections.Common.BaseDto' from assembly 'WE.GPR.Connections.Common, Version=1.0.22.0, Culture=neutral, PublicKeyToken=null'.
Could not load type 'WE.GPR.Connections.Common.BaseDto' from assembly 'WE.GPR.Connections.Common, Version=1.0.22.0, Culture=neutral, PublicKeyToken=null'.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart.get_Types()
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable`1 parts, ControllerFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetControllerTypes()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.get_ActionDescriptors()
at Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiVersionDescriptionProvider.EnumerateApiVersions(IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
at Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiVersionDescriptionProvider.LazyApiVersionDescriptions.EnumerateApiVersions()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at System.Lazy`1.get_Value()
at Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiVersionDescriptionProvider.get_ApiVersionDescriptions()
at WE.UserPortal.Api.Startup.<>c__DisplayClass5_0.<Configure>b__0(SwaggerUIOptions options) in D:\a\1\s\WE.UserPortal.Api\Startup.cs:line 130
at Microsoft.AspNetCore.Builder.SwaggerUIBuilderExtensions.UseSwaggerUI(IApplicationBuilder app, Action`1 setupAction)
at WE.UserPortal.Api.Startup.Configure(IApplicationBuilder app, IHostEnvironment env, IApiVersionDescriptionProvider provider) in D:\a\1\s\WE.UserPortal.Api\Startup.cs:line 127
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.Extensions.DependencyInjection.AutoRegisterMiddleware.<>c__DisplayClass4_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.WebHost.BuildApplication()