question

GeorgiKoemdzhiev-4063 avatar image
0 Votes"
GeorgiKoemdzhiev-4063 asked GeorgiKoemdzhiev-4063 commented

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

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


windows-server-iisdotnet-aspnet-core-generaldotnet-runtime
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Bruce-SqlWork avatar image
1 Vote"
Bruce-SqlWork answered GeorgiKoemdzhiev-4063 commented

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.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your comment, Bruce. I will see if I will be able to configure IIS as a reverse proxy (I think this would be the easiest at the moment).
I wanted to ask a follow-up question.

The Asp.Net Core 2.2 app above is a WebAPI as part of a solution together with a .NET Framework 4.7.2 MVC project (it also uses the BLL library above)

Currently, the solution is build/deployed by on an on-prem agent to an on-prem server with the following arguments using msbuild arguments:

 msbuild.exe MySolution.sln /p:DeployOnBuild=true;DeployTarget=PipelinePreDeployCopyAllFilesToOneFolder;PackageTempRootDir="bin\$(config)";AutoParameterizationWebConfigConnectionStrings=false /p:Configuration=$(config)

And the app works fine and does not complain about any missing packages




0 Votes 0 ·

With the current initiative, I am trying to migrate to the Cloud. As part of that, I am building/packaging the MVC site and WebAPI (.Net Core 2.2) app separately (not via the whole solution as the on-prem build agent) like that using a PowerShell script locally (for now):

 cd "${pwd}/Web.API/"
 dotnet.exe publish -o "${publishWorkspace}\website_web_api" /property:PublishProfile=FolderProfile /property:Configuration=$configName 
 cd ..
 msbuild.exe "${pwd}/.NetFrameworkWebsite.csproj" /target:package /property:Configuration=$configName /property:AutoParameterizationWebConfigConnectionStrings=False

After that combining the folders in a zip file for deployment. I am struggling to figure out if that difference in building/packaging is the cause for the problem?

0 Votes 0 ·
Bruce-SqlWork avatar image Bruce-SqlWork GeorgiKoemdzhiev-4063 ·

not sure why you would deploy core 2.2 code to the cloud. It has not received a security fix for almost 2 years.

you are also making use of a dropped feature (support of 4. libraries). you should convert the BLL to .net standard and remove its reliance on Microsoft.AspNet.SessionState.SessionStateModule as this an asp.net 4. feature only and not usable by the asp.net core code. Move the dependent code to its own project.

I'd upgrade to 3.1 before deploying to cloud.

1 Vote 1 ·
Show more comments