0
votes

I upgraded my web app to the latest Asp.net Core 2.1.1 and then I pushed it to Azure App Service from GitHub directly. When I accessed my site, I got 500 and the log is showing the following

System.BadImageFormatException: at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)

The docs on the exception itself is saying “The exception that is thrown when the file image of a dynamic link library (DLL) or an executable program is invalid.”, while others mentioned it's because Azure is using x86 version of the .net core.

Either way I could not figure out what exactly I need to do to resolve this issue. Thank you for any help on this.

2

2 Answers

1
votes

If this exception occurs for an Azure Apps deployment when upgrading an app and deploying newer assemblies, manually delete all files from the prior deployment.

Lingering incompatible assemblies can result in a System.BadImageFormatException exception when deploying an upgraded app.

Try to manually delete all files from the prior deployment.

For more details, you could refer to this article.

0
votes

This error can happen when your app dotnet core version is not aligned to the Azure Web app dot net core version. As an example, if try to deploy an app built with dotnetcore3.1 over a web application with dotnetcore3.0 runtime