Handler "aspNetCore" has a bad module "AspNetCoreModuleV2" in its module list

JDias 136 Reputation points
2025-01-14T17:07:21.1266667+00:00

I launched an app programmed in .NET Core 6 and React.js (with Vite.js) with Visual Studio, using the VS publish option and selecting the option Self-contained. This app uses the framework .NET 6.

The computer where I programmed has installed several .NET, such as 6.0. When I launched the app in the server (Windows Server 2012 R2, IIS 8.5), and accessed the page (https://{server ip}/) the app gave the error above: "Handler "aspNetCore" has a bad module "AspNetCoreModuleV2" in its module list"

The server has not the .NET 6, but since the app is self-contained (win-x64) I didn't bother.

The dotnet --info command (on the server) returns the existence of the following runtimes:

Microsoft.AspNetCore.All 2.1.15
Microsoft.AspNetCore.App 2.1.15
Microsoft.NETCore.App 2.1.15

When I openned the app page on Internet Explorer, it returned the following message:

HTTP Error 500.21 - Internal Server Error
Handler "aspNetCore" has a bad module "AspNetCoreModuleV2" in its module list

The app web.configfile (in the server app directory) contains:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath=".\FeriasForm.Server.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: 81ac978b-0566-4aa3-a798-43b0df2b3600-->

Note: no log file was produced in the directory .\logs.

If I run directly dotnet:

C:\ITF\FeriasForm>dotnet FeriasForm.Server.exe
Error:
  An assembly specified in the application dependencies manifest (FeriasForm.Ser
ver.deps.json) has already been found but with a different file extension:
    package: 'FeriasForm.Server', version: '1.0.0'
    path: 'FeriasForm.Server.dll'
    previously found assembly: 'C:\ITF\FeriasForm\FeriasForm.Server.exe'

If I run dotnetwith the dll:

C:\ITF\FeriasForm>dotnet FeriasForm.Server.dll
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\ITF\FeriasForm\
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
      Failed to determine the https port for redirect.	

I note that my application has a DLL with the same name as the EXE, even though the AI assistant suggests that shouldn't happen. My FeriasForm.Server.deps.json reffers the library DLL...

The server has .NET Core 2. Is this compatible with a self-contained .NET 6 app? May I install the runtime on the server without disrupt the .NET Core 2?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,776 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 71,101 Reputation points
    2025-01-14T17:29:42.9433333+00:00

    when you build a .net 6 app (now out of support), it creates a dll and on windows an .exe to run the dll. you can run the app via .exe or the dotnet.exe can run the dll. the .exe is a tiny C++ application that loads and runs the core dll.

    to host a .net 6 app in IIS you need to install the asp.net core IIS hosting module (AspNetCoreModuleV2). this is separate from the .net core install:

    https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-9.0

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2025-01-14T17:07:21.14+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The error message "Handler 'aspNetCore' has a bad module 'AspNetCoreModuleV2' in its module list" indicates that the ASP.NET Core Module (ANCM) is not properly configured or is missing on your server. Since you mentioned that the server does not have .NET 6 installed, this could be causing the issue, even though your application is self-contained.

    Here are some steps you can take to resolve the issue:

    1. Install the .NET Core Hosting Bundle: Ensure that the .NET Core Hosting Bundle for .NET 6 is installed on your server. This bundle includes the ASP.NET Core Module needed for hosting ASP.NET Core applications in IIS.
    2. Check the web.config file: Your web.config file specifies the use of AspNetCoreModuleV2. Ensure that the module is correctly installed. If the server has older versions of the ASP.NET Core Module, it may not support your application.
    3. Verify the Application Pool: Make sure that the application pool for your application is set to "No Managed Code" since you are using a self-contained deployment.
    4. Check for Conflicting Assemblies: The error message you received when running dotnet FeriasForm.Server.exe suggests that there may be conflicting assemblies. Ensure that your deployment does not contain both the .exe and .dll files for the same application.
    5. Log Files: Since no log file was produced in the .\logs directory, ensure that the directory exists and that the application has permission to write to it.
    6. Run the Application Locally: If possible, run the application locally using Kestrel to ensure that it functions correctly outside of IIS.

    Following these steps should help you resolve the issue with the ASP.NET Core application on your server.


    References:

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.