The Module "aspnetcorev2.dll" failed to load

Viewed 16850

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?

5 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.

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://docs.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://docs.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://docs.microsoft.com/en-us/dotnet/core/tools/global-json

I had this same error on a new install of Windows 7 & I looked it up & found that it was indeed the missing update. To fix it you just need to download & install KB2999226 from https://www.microsoft.com/en-us/download/details.aspx?id=49077 (ie. this is for windows 7) & the problem was fixed directly. you didn’t need to go & download/install the whole Microsoft Visual C++ Redistributable package. No reboot either worked in a few minutes. you don’t need to have the 2015 nor 2017 packages installed, just 2013, 2010, 2008 & 2005 is enough.

I noticed that C:\Program Files\IIS\Asp.Net Core Module indeed did not exist on my machine. I just copied over C:\Program Files\IIS Express\Asp.Net Core Module (elevated) which did exist and... the Application Pool started fine!

See what worked for me in my answer on https://stackoverflow.com/a/73640078/993991. How I ended up uninstalling v2 of ASP.NET Core, but the same steps could be adapted to point to a newer version or at least the installed version.

Related