Question IIS Error HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure

bronstein

New member
Joined
Jul 18, 2022
Messages
2
Programming Experience
1-3
Hello, everyone,
I've been trying to get my project running on an IIS server under Windows Server 2019 for days now.

I set .net Core 3.1 as the target framework in Visual Studio


Since I'm using a 32-bit DLL, I set 32-bit to true in the IIS Application Pool


It runs under Visual Studio with IIS Express, but if I publish it now and want to start it on the server, I get the following message in the browser:
HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure


In the log file I see the following message:
Unhandled exception. System.BadImageFormatException: Could not load file or assembly 'C:\inetpub\Test_Services\test.dll'. An attempt was made to load a program with an incorrect format. File name: 'C:\inetpub\Test_Services\test.dll'

My csproject file looks like this:
Error:
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
    <Platforms>AnyCPU;x86</Platforms>
    <UserSecretsId>f3492274-f87e-402b-ad37-821f94564fcd</UserSecretsId>
    <StartupObject>test.Program</StartupObject>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <Prefer32Bit>true</Prefer32Bit>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
    <Prefer32Bit>true</Prefer32Bit>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
    <Prefer32Bit>true</Prefer32Bit>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Cors" />
    <!-- <PackageReference Include="Microsoft.AspNetCore.All" Version="3.1.27" /> -->
    <PackageReference Include="System.Private.ServiceModel" Version="4.9.0" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.9.0" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.9.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.9.0" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.9.0" />
  </ItemGroup>

  <ItemGroup>
    <WCFMetadata Include="Connected Services" />
  </ItemGroup>

  <ProjectExtensions><VisualStudio><UserProperties properties_4launchsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>


</Project>

The Web.config:
Web.config::
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\test.dll" stdoutLogEnabled="true"
        stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
    <!--<system.webServer>
        <aspNetCore processPath="dotnet" arguments=".\test.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
            <handlers>
                <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified"/>
            </handlers>
            <handlerSettings>
                <handlerSetting name="stackSize" value="2097152"/>
            </handlerSettings>
        </aspNetCore>
    </system.webServer>-->
    <!-- <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\test.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    </system.webServer>
  </location> -->
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding openTimeout="00:10:00" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00"/>
            </wsHttpBinding>
        </bindings>
    </system.serviceModel>
    <system.net>
        <!-- erstmal herausnhemen zum test<defaultProxy>
      <proxy autoDetect="false" bypassonlocal="false" proxyaddress="http://127.0.0.1:8888" usesystemdefault="false" />
    </defaultProxy> -->
    </system.net>
</configuration>

Attached are a few pictures of the settings and installations
 

Attachments

  • Installation.png
    Installation.png
    87.4 KB · Views: 6
  • IIS_configuration.png
    IIS_configuration.png
    80.5 KB · Views: 6
  • publish.png
    publish.png
    11.2 KB · Views: 6
  • projectsettings.png
    projectsettings.png
    4.5 KB · Views: 5

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,469
Location
Chesapeake, VA
Programming Experience
10+
Your .NET CLR version setting in IIS should be "No managed code".

Once you change that and it still doesn't work, check the "logs\stdout" for any logs that give you more of a hint as to what is failing.

As an aside, .NET Core 3.1 hits end of life this Dec 13, 2022. You'll need to plan ahead on porting to .NET 6.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,469
Location
Chesapeake, VA
Programming Experience
10+
Oh, another thing. On the IIS server, check to see whether the 32-bit or the 64-bit version of .NET Core was installed. If the server owner installed the ".NET Core Hosting bundle", both should be present.
 

bronstein

New member
Joined
Jul 18, 2022
Messages
2
Programming Experience
1-3
I have changed it to ""No managed code" but i get the same error

Attached are picture with the installed .net Version in 32 and 64 bit

Does anythimng missing?
 

Attachments

  • Installation2.png
    Installation2.png
    169.8 KB · Views: 1

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,469
Location
Chesapeake, VA
Programming Experience
10+
Try changing the processPath="dotnet" to processPath="C:\Program Files (x86)\dotnet\dotnet".

If that fails, and you have a corresponding "test.exe" for your "test.dll" as part of your publishing output, try removing arguments and changing processPath to processPath="C:\inetpub\Test_Services\test.exe" .

If that still fails revert back to the original values for processPath and argumets, and run the SysInternals Process Monitor to see which version of dotnet.exe it is trying to use. Is it the dotnet.exe in the "Program Files (x86)" folder, or is it the one in the "Program Files" folder?
 
Top Bottom