Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Module "aspnetcorev2.dll" failed to load

Recently I tried installing ASP.NET Core/.NET Core: Runtime & Hosting Bundle version 2.2 on a machine running Windows Server 2008 R2 SP1. However, after installing IIS stops working and gives 503 Service unavailable error for all applications hosted in it. After checking the application pools I see that the pools just shuts down.

In the event viewer I can see the following error message -

The Module DLL C:\Program Files (x86)\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll failed to load. The data is the error.

I have tried setting the pool to both 32/64 bits, but the error is the same. Did anybody else face this problem or have solution for this?

like image 957
th1rdey3 Avatar asked Jan 14 '19 06:01

th1rdey3


2 Answers

After reading through the following documents -

Troubleshoot ASP.NET Core on IIS

and

Common errors reference for Azure App Service and IIS with ASP.NET Core

I came to know that the ASP.NET Core/.NET Core: Runtime & Hosting Bundle (latest versions) depends on Microsoft Visual C++ 2015 Redistributable. The machine in question had earlier versions of vc++ redist installed. After installing the said version of redistributables (both 32 & 64 bit) everything started working again.

Funny thing is the ASP.NET Core/.NET Core: Runtime & Hosting Bundle Version 2.2 installer didn't throw any errors or warnings during installation about the missing vc++ 2015 redist.

like image 183
th1rdey3 Avatar answered Nov 12 '22 21:11

th1rdey3


That aspnetcorev2.dll is actually ASP.NET Core 2.0 Module, commonly called ANCM. This module needs some setup and configuration if the ASP.NET Core 2.0/2.1/2.2 is going to be run on top of IIS and use IIS as the main proxy before going to ASP.NET Core original Kestrel engine, and it's also called out-of-process model.

This is important, on other platforms other than Windows, all request goes directly to Kestrel and served by Kestrel directly. Therefore on IIS, a special configuration setup need to be done to use Kestrel on IIS.

For more information about ANCM on IIS, please consult this official Microsoft Docs: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.2

NOTE: although that page is for .NET Core 2.2, it's still applicable for .NET 2.0/2.1.

Based on your error, there's a chance that the ANCM DLL is not within the reach of the resulting DLL of your app. Ensure that the ANCM dll files are within your resulting compiled folder, not outside. Also ensure that you're using RTM or official release version of .NET Core 2.0/2.1/2.2 runtime instead of daily build, because using daily build of .NET Core 2.0/2.1/2.2 may bring some strange errors because their full distribution of runtime DLLs may not be fully coherent.

For more information about troubleshooting ANCM in ASP.NET Core 2.x, please consult this official MS Docs: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/troubleshoot?view=aspnetcore-2.2

UPDATE #1:

Based on comment below, I add this additional info: you should clear all nuget caches on your machine, restore and run MSBUILD again. If you use .NET Core 2.1 as the platform for your ASP.NET Core 2.1 app, then if you install .NET Core 2.2 without updating references of your app to v2.2, there's a chance that references still mixed up.

Or for better practice, use global.json file to strict your compilation of your app to always use .NET Core 2.1 SDK with specific version, regardless what is the latest version of .NET Core SDK you have on your machine. This is also important, because by default compiling .NET Core app will always try to use the latest SDK available on your machine, and previous existing older version will be ignored.

Setting up global.json is documented here: https://learn.microsoft.com/en-us/dotnet/core/tools/global-json

like image 1
Eriawan Kusumawardhono Avatar answered Nov 12 '22 20:11

Eriawan Kusumawardhono