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

0

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
    }
  }
}

But that does not fix the problem (exactly the same message), and it contain nothing about the .Net requirements of the project.

So I attempted to modify the file with things like

 {
  "runtimeOptions": {
      "framework": {
        "name": "Microsoft.NET",
        "version": "net472"
    },
    "configProperties": {
      "System.GC.Server": true,
      "Microsoft.NETCore.DotNetHostPolicy.SetAppPaths": true
    }
  }
 }

and some variants ("name": "Microsoft.NETCore.App", "version": "2.1.2"), but it fails with completely different errors.

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

As said previously, the same application works well in IIS. "System.Memory" is shipped along the EXE, and is in version 4.5.1 (according nuget) with no problem.

I am unable to figure the good values to set in this file to host a MVC Core .Net 4.7 application in Azure, could you please help ? Thank you

asp.net
.net
azure
asp.net-core-mvc
azure-web-sites
asked on Stack Overflow Oct 4, 2018 by AFract

1 Answer

1

I am answering myself lately : according somebody in the team and as our tests have confirmed, the problem had nothing to do with "runtime" config file, it was related to have the connection string in configuration file. Move it elsewhere and the application will start as expected.

Lot of time lost on this, that's a shame Microsoft didn't handled this better in terms of error message.

answered on Stack Overflow Oct 24, 2018 by AFract

User contributions licensed under CC BY-SA 3.0