Could not load file or assembly 'Microsoft.AspNet.SessionState.SessionStateModule' on IIS 10 .Net Core app using .Net Framework library

Georgi Koemdzhiev 61 Reputation points
2021-10-26T12:56:33.683+00:00

My project has the following structure:

  • BLL.Net Framework (classic) library. It uses Microsoft.AspNet.SessionState.SessionStateModule NuGet package
  • Web.API.Net Core 2.2 app that uses the BLL library

When I deploy the app to IIS (I use AWS Beanstalk) and try to access it via URL 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. 

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Windows\SysWOW64\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\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\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/Framework/v4.0.30319/Temporary ASP.NET Files/api/cdac803f/2976b187/Microsoft.AspNet.SessionState.SessionStateModule.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/api/cdac803f/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/Framework/v4.0.30319/Temporary ASP.NET Files/api/cdac803f/2976b187/Microsoft.AspNet.SessionState.SessionStateModule.EXE.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/api/cdac803f/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.

When I looked into the Fusion (Assembly Binder) logs I this No matching native image found message:

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Windows\SysWOW64\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/wwwroot/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\26676eb7
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\26676eb7
LOG: AppName = 92c7e946
Calling assembly : (Unknown).
===
WRN: No matching native image found.
LOG: IL assembly loaded from C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\26676eb7\92c7e946\assembly\dl3\0539d1ab\00aed40e_68c3d201\Microsoft.AspNet.SessionState.SessionStateModule.dll.

Note: when I run the all using this command on the IIS server it works fine:

PS C:\inetpub\AspNetCoreWebApps\BackendAPI> dotnet Web.Api.dll environment=Development
Hosting environment: Development
Content root path: C:\inetpub\AspNetCoreWebApps\BackendAPI
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001

I am not sure how the app starts fine when I start it outside IIS server like that but I thought it may be helpful to mention

Also, I am building my .Net core app using this command: dotnet.exe publish -o "~\website_web_api" /property:Configuration=Debug

Internet Information Services
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,207 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,126 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 56,931 Reputation points
    2021-10-26T15:42:27.407+00:00

    core 2.2 (end of life 12/12/2019) was an experiment in supporting 4.* dll's. This support has been dropped in current versions of .net core. I would guess that it is a limitation of the AspNetCore hosting module that is loading the dlls rather the the dotnet.exe

    be sure to configure the hosting module for out-of-process. if this doesn't work, start the core app outside of IIS and configure IIS as a reverse proxy.

    You really should convert your BLL library to .net standard or core. as asp.net core does not support the Microsoft.AspNet.SessionState.SessionStateModule anyway, you should remove the dependancy.

    you should also move from 2.2 to a supported version of .net core. at this point the .net 6 LTS is due in a couple weeks, but 3.1 LTS is supported for another year.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful