4
votes

Trying to migrate the projects from .net core 2.2 to 3.1. In local debug the whole application works correctly. I've tried to publish my application on IIS. After publishing I go to the site url and see the error:

Error 500.31 - ANCM Failed to Find Native Dependencies in IIS

Common solutions to this issue: The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.

Specific error detected by ANCM: A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in

dotnet --info command result:

dotnet --info

All projects has the target framework .netcoreapp 3.1, libraries are .netstandart 2.0. I've tried re-installing SDK, Visual Studio 2019. I've updated every nuget packages from 2.2 to 3.1.1, that are connected with Microsoft.

Hosting bundle 3.1.1 is also installed. Any ideas how to solve this problem?

UPD. The publish command:

dotnet publish $projectPath -m --no-build -c:$publishConfiguration -o $destinationPath -v q -r $targetPlatform /p:EnvironmentName=$publishEnvironment --self-contained false;

target-platform = win-x64. The hosting model is InProgress.

UPD 2. The result of dotnet list package on solution: https://gist.github.com/AndreiKhotko/60aafeb42566ac3e3fadfab2d0209dde

UPD 3. The ASP.NET Core Diagnostics generated report: https://gist.github.com/AndreiKhotko/2a193b4121c4399e0a00bfef708140da

UPD 4. Sorry, I haven't specified the whole error message. There is the last part of it (see above for the first part of it):

Failed to run as a self-contained app. If this should be a framework-dependent app, specify the appropriate framework in '*.runtime.config'.

The content of *.runtime.config:

{
  "runtimeOptions": {
    "tfm": "netcoreapp3.1",
    "includedFrameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "3.1.1"
      },
      {
        "name": "Microsoft.AspNetCore.App",
        "version": "3.1.1"
      }
    ],
    "configProperties": {
      "System.GC.Server": true
    }
  }
}
1
Can you do a dotnet list package in the solution directory and create a gist of the results? - Martin Frøhlich
@MartinFrøhlich sure. I will notice you after updating the question - Andrei Khotko
@MartinFrøhlich check it out. Now I see that there are the packages .net Tests with version 16.0. Seems like these references breaks the publishing. I will check it later - Andrei Khotko
@JalpaPanchal change module to AspNetCoreModule is not good idea. Event viewer shows the same errors. Their descriptions are useless - Andrei Khotko
Please remove --self-contained false from the publish command. Why do you want to disable that while choosing win-x64? That only leaves the generated binaries in inconsistency. - Lex Li

1 Answers

2
votes

The cause is that dotnet publish has very ambiguous behaviors when a combination of switches are served.

In your case, --self-contained false and -r linux-x64 are kind of conflicting to each other. -r linux-x64 forces to generate self-contained binaries, while --self-contained false seems to remove important runtime dependencies from the final files. It is too bad that the dotnet CLI does not give you a warning/error for that.

If your goal is to use framework dependent deployment, follow the instructions strictly, https://docs.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli#framework-dependent-deployment and remove -r linux-x64 from your command.