0

I have a .Net Core 2.2 project (web API) that uses as a dependency a .Net Framework 4.7.2 (classic) library.

Project structure:

  • BLL (classic library, it uses Microsoft.AspNet.SessionState.SessionStateModule nuget package)
  • Web.API.(Net Core app)

I build the .Net Core app using the below command:

dotnet.exe publish -o "${publishWorkspace}\website_web_api" /property:Configuration=Debug

When I deploy the project on AWS Beanstalk (IIS 10.0 running on 64bit Windows Server 2016/2.7.2) I get this error when I try to access the API URL:

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. 

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

this is the problematic NuGet package reference in the "BLL" .Net Framework library csproj:

...
 <Reference Include="Microsoft.AspNet.SessionState.SessionStateModule, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <HintPath>..\packages\Microsoft.AspNet.SessionState.SessionStateModule.1.1.0\lib\Net462\Microsoft.AspNet.SessionState.SessionStateModule.dll</HintPath>
    </Reference>
...

I tried adding the bindingRedirect to the BLL.dll.config and restarting IIS server but that did not help:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
...
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNet.SessionState.SessionStateModule" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /></startup></configuration>

Installed SDKs on the AWS Beanstalk instance:

PS C:\Users\Administrator> dotnet --list-sdks
2.1.818 [C:\Program Files\dotnet\sdk]
3.1.413 [C:\Program Files\dotnet\sdk]        
5.0.401 [C:\Program Files\dotnet\sdk]        

According to AWS docs it should support those .Net versions:

  • .NET 5.0.11, supports 5.0.11, 3.1.20, 2.1.30
  • .NET Framework 4.8, supports 4.x, 2.0, 1.x

UPDATE

I tried to run the deployed API app using the terminal by running dotnet .\Web.API.dll environment=Development

That returned this error:

The framework 'Microsoft.AspNetCore.App', version '2.2.0' was not found.
  - The following frameworks were found:
      2.1.30 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      3.1.19 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      5.0.10 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]

So I installed the 2.2 Runtime (via the hosting bundle from here) and then retried the above command and this time it ran fine and started listening for requests.

However, when I tried to use the URL that I set up for the API project via the IIS server, I get the same "Could not load file or assembly 'Microsoft.AspNet.SessionState.SessionStateModule" error.

I tried restarting the IIS Server as well, no luck

UPDATE 2

After enabling "Fusion!EnableLog" logging (see this question). I got some more info regarding the assembly load problem:

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.

I suspect the issue is that there is no bin folder in the location where the API project is deployed but not sure why that is the case

Georgi Koemdzhiev
  • 11,421
  • 18
  • 62
  • 126
  • 1
    1. .NET Core 2.2 is end of life. 2. Never consume a .NET Framework assembly in a .NET Core project (exceptions are rare and only a guru knows what he/she is doing). So in your case, get rid of that dependency is your only option, because clearly it was only designed for the old ASP.NET. – Lex Li Oct 25 '21 at 14:09
  • Thank you for your response. I do plan to migrate that .Net Framework library to .Net Core 3.1 but I am hoping to figure out a way to make it work for the time being. Please see the "UPDATE 2" section I just added – Georgi Koemdzhiev Oct 25 '21 at 15:03
  • You won't find a way when that's a dead end. – Lex Li Oct 25 '21 at 16:29
  • The bit that I do not understand (see Update 1) is that when I run the app using the `dotnet wepapi.dll` command the app starts and listens for requests. I do not get the above file not found exception – Georgi Koemdzhiev Oct 25 '21 at 16:49
  • Set the "Enable 32-bit applications" to "true" in advanced settings of iis application pool and try again. – samwu Oct 26 '21 at 09:44
  • Thanks @samwu I tried that already, it is set to `True` currently but I still get the error – Georgi Koemdzhiev Oct 26 '21 at 09:53
  • [https://learn.microsoft.com/en-us/answers/questions/609484/could-not-load-file-or-assembly-39microsoftaspnets-1.html](https://learn.microsoft.com/en-us/answers/questions/609484/could-not-load-file-or-assembly-39microsoftaspnets-1.html). – samwu Nov 18 '21 at 09:24

0 Answers0