Could not load file or assembly 'Microsoft.AspNet.SessionState.SessionStateModule' when accessing .Net core api via "/api" virtual path

Georgi Koemdzhiev 61 Reputation points
2021-10-29T16:44:34.113+00:00

I deployed the following apps:

  • ASP.NET MVC (.Net Framework 4.7.2) site
  • .Net Core 3.1 web API

both on the same IIS server. The site is set up to "/" path and the API to "/api":
145064-image.png

Accessing the website from, for example, from localhost opens site fine. However, if I try to access the API (e.g. http://localhost/api) I get this error:

Could not load file or assembly 'Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.   
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.   
  
 Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.  
  
Source Error:   
  
 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.     
  
Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.  
  
Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll  
Running under executable  c:\windows\system32\inetsrv\w3wp.exe  
--- A detailed error log follows.   
  
=== Pre-bind state information ===  
LOG: DisplayName = Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35  
 (Fully-specified)  
LOG: Appbase = file:///C:/inetpub/AspNetCoreWebApps/BackendAPI/  
LOG: Initial PrivatePath = C:\inetpub\AspNetCoreWebApps\BackendAPI\bin  
Calling assembly : (Unknown).  
===  
LOG: This bind starts in default load context.  
LOG: Using application configuration file: C:\inetpub\AspNetCoreWebApps\BackendAPI\web.config  
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config  
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.  
LOG: Post-policy reference: Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35  
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/api/27eecc96/2976b187/Microsoft.AspNet.SessionState.SessionStateModule.DLL.  
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/api/27eecc96/2976b187/Microsoft.AspNet.SessionState.SessionStateModule/Microsoft.AspNet.SessionState.SessionStateModule.DLL.  
LOG: Attempting download of new URL file:///C:/inetpub/AspNetCoreWebApps/BackendAPI/bin/Microsoft.AspNet.SessionState.SessionStateModule.DLL.  
LOG: Attempting download of new URL file:///C:/inetpub/AspNetCoreWebApps/BackendAPI/bin/Microsoft.AspNet.SessionState.SessionStateModule/Microsoft.AspNet.SessionState.SessionStateModule.DLL.  
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/api/27eecc96/2976b187/Microsoft.AspNet.SessionState.SessionStateModule.EXE.  
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/api/27eecc96/2976b187/Microsoft.AspNet.SessionState.SessionStateModule/Microsoft.AspNet.SessionState.SessionStateModule.EXE.  
LOG: Attempting download of new URL file:///C:/inetpub/AspNetCoreWebApps/BackendAPI/bin/Microsoft.AspNet.SessionState.SessionStateModule.EXE.  
LOG: Attempting download of new URL file:///C:/inetpub/AspNetCoreWebApps/BackendAPI/bin/Microsoft.AspNet.SessionState.SessionStateModule/Microsoft.AspNet.SessionState.SessionStateModule.EXE.  
  
Stack Trace:   
  
[FileNotFoundException: Could not load file or assembly 'Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]  
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0  
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +96  
   System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +65  
   System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +62  
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +50  
  
[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]  
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +572  
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, Boolean checkAptcaBit) +31  
   System.Web.Configuration.Common.ModulesEntry.SecureGetType(String typeName, String propertyName, ConfigurationElement configElement) +59  
   System.Web.Configuration.Common.ModulesEntry..ctor(String name, String typeName, String propertyName, ConfigurationElement configElement) +59  
   System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +221  
   System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +1103  
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +122  
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +173  
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +255  
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +347  
  
[HttpException (0x80004005): Could not load file or assembly 'Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]  
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +552  
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +122  
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +737  
  

dotnet --info output on the server:

PS C:\Users\Administrator> dotnet --info  
.NET SDK (reflecting any global.json):  
 Version:   5.0.401  
 Commit:    4bef5f3dbf  
  
Runtime Environment:  
 OS Name:     Windows  
 OS Version:  10.0.14393  
 OS Platform: Windows  
 RID:         win10-x64  
 Base Path:   C:\Program Files\dotnet\sdk\5.0.401\  
  
Host (useful for support):  
  Version: 5.0.10  
  Commit:  e1825b4928  
  
.NET SDKs installed:  
  2.1.818 [C:\Program Files\dotnet\sdk]  
  3.1.413 [C:\Program Files\dotnet\sdk]  
  5.0.401 [C:\Program Files\dotnet\sdk]  
  
.NET runtimes installed:  
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]  
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]  
  Microsoft.AspNetCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]  
  Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]  
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]  
  Microsoft.NETCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]  
  Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]  
  Microsoft.WindowsDesktop.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]  
  Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]  

The strange thing is that the API project (.Net Core 3.1) does not use "Microsoft.AspNet.SessionState.SessionStateModule" package at all. However, this SessionStateModule package is used by the .Net Framework site (via a classic/4.7.2 library).

I do not understand why the assembly binder (i.e. Fusion) is looking for that package in the "C:\inetpub*BackendAPI\bin folder. There is no "bin" folder where the .Net Core 3.1 app is deployed at all (see LOG: Initial PrivatePath = C:\inetpub\AspNetCoreWebApps\BackendAPI\bin).

What am I missing here? Have a messed up the deployment of those 2 apps somehow?

Thank you in advance

Windows development Internet Information Services
Developer technologies ASP.NET ASP.NET Core
Developer technologies .NET .NET Runtime
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 60,161 Reputation points
    2021-10-29T17:52:39.923+00:00

    That isn't going to work. Your main app is hosted by .NET Framework. That is what the app pool is running. You are then trying to host a child app using .NET Core. You can have 2 child apps running different versions of the runtime but the scenario you are trying isn't supported AFAIK.

    Separate your main site from the api and host them in 2 different apps under the default web site. You can using bindings on the default site if you need to make them accessible using specific DNS names. Alternatively move the API to its own site altogether and use bindings to manage traffic to each site.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2021-10-29T19:50:19.397+00:00

    I tried your config. asp.net 4.8 application with an api folder (app) hosting a core 3.1 webapi application

    it looks like you did not create the api application correctly

    it should be a new Application with its own unique app pool set to no managed code
    the physical path should be a folder that the core 3.1 app published to. (should not be a subfolder of the parent site). looking at your logs it should probably be:

    c:\inetpub\AspNetCoreWebApps\BackendAPI

    there should just be a web.config, and the app.exe and depend dll's in the folder. the web.config should look like:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <location path="." inheritInChildApplications="false">
        <system.webServer>
          <handlers>
            <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
          </handlers>
          <aspNetCore processPath="dotnet" arguments=".\backendapi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
        </system.webServer>
      </location>
    </configuration>
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.