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