Appropriate content for Myapp..runtimeconfig.json configuration file for a .Net 4.7 app on Azure

AFr*_*act 5 .net asp.net azure asp.net-core-mvc azure-web-app-service

I'm new with Azure and a bit confused by a few things. I am unable to have my MVC Core application working properly on it.

The app is a MVC .Net Core 2.1 application, targetting .Net 4.7.2 framework (not .Net Core), with a rather complex dependency graph.

With local IIS Express, it works perfectly, and it also works when I publish it with Visual Studio on local IIS instance (with AspNetCoreModule installed).

But when I try to publish it on Azure, publish goes well but application fails at startup (502.5, process failure).

When I start the EXE from Azure Console, I encounter the error :

A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'D:\home\site\wwwroot\'.

Failed to run as a self-contained app. If this should be a framework-dependent app, specify the appropriate framework in D:\home\site\wwwroot\xxx.runtimeconfig.json.

I added the file manually, and I have also attempted to make it published automatically by Visual Studio by adding <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> inside the project.

It generates the following file :

{
  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true,
      "Microsoft.NETCore.DotNetHostPolicy.SetAppPaths": true
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但这并不能解决问题(完全相同的消息),并且它不包含有关项目的 .Net 要求的任何内容。

所以我尝试用类似的东西修改文件

 {
  "runtimeOptions": {
      "framework": {
        "name": "Microsoft.NET",
        "version": "net472"
    },
    "configProperties": {
      "System.GC.Server": true,
      "Microsoft.NETCore.DotNetHostPolicy.SetAppPaths": true
    }
  }
 }
Run Code Online (Sandbox Code Playgroud)

和一些变体("name": "Microsoft.NETCore.App", "version": "2.1.2"),但它失败并出现完全不同的错误。

Unhandled Exception: System.TypeInitializationException: The type initializer for 'xxx.UI.Program' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Memory, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at System.IO.DirectoryInfo.Init(String originalPath, String fullPath, String fileName, Boolean isNormalized)
   at NLog.Internal.AssemblyHelpers.GetAssemblyFileLocation(Assembly assembly)
   at NLog.LogFactory.GetDefaultCandidateConfigFilePaths()+MoveNext()
   at NLog.LogFactory.TryLoadFromFilePaths()
   at NLog.LogFactory.get_Configuration()
   at NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey)
   at NLog.LogFactory.GetLogger(String name)
   at NLog.LogManager.GetCurrentClassLogger()
   at xxx.UI.Program..cctor() in C:\xxx\xxx.UI\Program.cs:line 14
   --- End of inner exception stack trace ---
   at xxx.UI.Program.Main(String[] args) in C:\xxx\xxx.UI\Program.cs:line 28
Run Code Online (Sandbox Code Playgroud)

如前所述,同一应用程序在 IIS 中运行良好。“System.Memory”随 EXE 一起提供,并且在版本 4.5.1(根据 nuget)中没有问题。

我无法确定在此文件中设置的合适值以在 Azure 中托管 MVC Core .Net 4.7 应用程序,您能帮忙吗?谢谢

AFr*_*act 4

我最近回答自己:根据团队中的某人的说法,正如我们的测试所证实的那样,问题与“运行时”配置文件无关,它与配置文件中的连接字符串有关。将其移至其他位置,应用程序将按预期启动。

在这方面浪费了很多时间,遗憾的是微软没有在错误消息方面更好地处理这个问题。