TypeLoadException: Could not load type 'System.Web.HttpContextBase' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Benjamin Sims 21 Reputation points
2022-07-21T19:20:46.647+00:00

I've been working on migrating a .NET Framework 4.7.2 project to .NET 6. After running through the upgrade assistant, upgrading packages, and migrating code to the .NET 6 equivalent, I'm getting this error with this full callstack:

System.TypeLoadException: Could not load type 'System.Web.HttpContextBase' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.  
   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)  
   at System.Reflection.RuntimePropertyInfo.get_Signature()  
   at System.Reflection.RuntimePropertyInfo.get_PropertyType()  
   at Microsoft.Extensions.Internal.PropertyHelper.IsRefStructProperty(PropertyInfo property)  
   at Microsoft.Extensions.Internal.PropertyHelper.IsInterestingProperty(PropertyInfo property)  
   at Microsoft.Extensions.Internal.PropertyHelper.<>c.<GetProperties>b__44_0(PropertyInfo p)  
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.ToArray()  
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)  
   at Microsoft.Extensions.Internal.PropertyHelper.GetProperties(Type type, Func`2 createPropertyHelper, ConcurrentDictionary`2 cache)  
   at Microsoft.Extensions.Internal.PropertyHelper.GetProperties(Type type)  
   at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultApplicationModelProvider.OnProvidersExecuting(ApplicationModelProviderContext context)  
   at Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModelFactory.CreateApplicationModel(IEnumerable`1 controllerTypes)  
   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.Routing.AttributeRoute.GetTreeRouter()  
   at Microsoft.AspNetCore.Mvc.Routing.AttributeRoute.RouteAsync(RouteContext context)  
   at Microsoft.AspNetCore.Routing.RouteCollection.RouteAsync(RouteContext context)  
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)  
   at Web.BenefitScreenings.Startup.<>c.<<Configure>b__5_1>d.MoveNext() in D:\*Redacted*\Startup.cs:line 212  
--- End of stack trace from previous location ---  
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)  
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)  
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)  

Visual Studio isn't breaking anywhere in the debugger. I've tried dotnet clean/restore/build, deleting the bin folder, and verifying all packages are upgraded and no version conflicts are happening. When I remove the bit of code on Startup.cs:line 212 it throws the same exact error.

Does anyone have any troubleshooting steps to see what the issue could be?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,079 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,098 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 53,501 Reputation points
    2022-07-21T22:14:10.86+00:00

    looks like the System.Web.dll is being referenced and it is not supported in net 6.

    for all projects in the solution:

    be sure you removed all Microsoft.Aspnet.*, and Microsoft.Web.Infrastructure nuget packages
    be sure there are no references to System.Web.dll

    delete *.obj and *.bin in the projects

    then do a rebuild

    check that the system.web.dll is not in the bin folder (if there is you missed a reference).

    if you still get the error you missed a reference:

    go through the nuget packages in the solution and be sure there is .netstandard or .net core version of each package. if not remove the package and find a replacement.

    note: the stack trace suggests your controller (or one of references) has reference to system.web. Maybe you had a helper routine that accessed session or httpcontext.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Saif Quraishi 1 Reputation point
    2022-12-28T06:55:50.487+00:00

    @Bruce (SqlWork.com) Hi thanks for the suggestion, I had follows your all step but still getting same error as mention above.

    @Benjamin Sims hi did you resolve your issue?

    0 comments No comments