How to change Azure App Service to 64-bit
Asked Answered
D

6

36

I have been having trouble making a request to my 64-bit ASP.NET Core API running on an Azure App Service. The error I get back is:

Unhandled Exception: System.BadImageFormatException: Could not load file or assembly '***.dll'. An attempt was made to load a program with an incorrect format.

I understand that this means there is a mismatch between the platform of the app (64-bit) and that of the environment it runs on. I just can't figure out how to change the App Service so it runs using 64-bit.

In the Application Settings in the Azure portal I have set Platform to 64-bit:

enter image description here

However when I check in Kudu, the runtime environment indicates that it's operating under win8-x86:

enter image description here

project.json

"buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "platform": "x64"
},

"runtimes": {
    "win10-x64": {}
}

Some questions

  1. How do I change the App Service to ensure it's running on a 64-bit platform?
  2. Does it matter that the RID is win8... when my runtimes configuration in project.json specifies win10.... Presumably x86 vs x64 matters, but does it need to be the same version of windows too ie. win8 vs win10.
Duntson answered 10/3, 2017 at 19:32 Comment(3)
I am having the same issue. Is there any update on this?Syck
@TamasPataky Thanks for reminding me - I'll update with an answer I got from supportDuntson
Fixed it by setting the in the Publish Profile the target to win-x64Pneumograph
T
17

This is now available in Azure App Service.

Steps to deploy:

  1. Set platform to 64-bit in portal
  2. Ensure the project targets 64-bit by including the following in the csproj:
<PropertyGroup>
  <PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
  1. When publishing application ensure target framework is set to win-x64. (If running dotnet publish just add -r win-x64)

The documentation is here but (at present) it is acknowledged to be a little sparse.

This github issue response suggests we should be able to do a framework dependent deployment and have it "just work". YMMV but that wasn't my own experience hence the runtime flag suggestion above

Topnotch answered 5/7, 2019 at 9:34 Comment(6)
I cannot set Platform to 64-bit in portal with free planUnctuous
This was surprisingly hard to figure out. After reading everything everywhere this was the only documentation I found saying that you had to specifically set the platform architecture on azure itself.Petit
but im using publish profile to deploy web-app not any commandNicotiana
You'll nee to build with -r win-x64 as well.Gilbertgilberta
How would this work if my local machine I do dev on is a MacBook Pro M1 (needing PlatformTarget Arm64), but the Azure Service Plan we deploy to is a Windows (needing PlatformTarget win-x64)?Dotation
Wouldn't <PlatformTarget>AnyCPU</PlatformTarget> suffice?Abstergent
D
15

TLDR; 64 bit .NET core processes using the .NET core runtime (as opposed to the .NET Framework runtime) are not yet supported on Azure but is planned to be coming in the future.


The following is from discussions I had with Microsoft Azure support.

The 64bit/32bit configuration on Azure portal (shown above in my screenshot), controls the IIS w3wp.exe process. The w3wp.exe process forwards requests to your NET core process. The configuration doesn't control the bitness of the .NET core process. It's a bit confusing, but explains why changing the Platform option in the screneshot above had no affect.

Based on the PATH environment variable setting of app service, dotnet.exe is mapped to the 32bit one, which is "D: \Program Files (x86)\dotnet\dotnet.exe". The 64bit runtime of .NET core is not pre-installed in app services, as a result, it is currently not available.

Microsoft is planning to add 64-bit support to .NET core applications running on the .NET core runtime in Azure but it depends on a future update of the .NET core tools chain. They gave me an estimated internal date but I promised I wouldn't share that publicly.

A workaround they gave me was to use the ASP.NET core (using .net framework) visual studio template, not the ASP.NET core (using .net core) one. That one loads the 64bit .Net framework runtime for your ASP.Net core web application. This will require a bit of migration work and I assume may not be possible for some projects.

Fortunately I was able to swap to 32 bit versions of some of my dependencies which meant the app worked in the Azure environment. Sadly this won't mean much to those that don't have this option, and I'm sure there are many.

Duntson answered 8/6, 2017 at 11:3 Comment(1)
Here's the best ETA I was able to find. It was moved to "planned" 6 months ago, but no updates since: feedback.azure.com/forums/169385-web-apps/suggestions/…Ramirez
L
11

If you need a 64 bit runtime, there are 4 ways to do this:

  1. Deploy a self-contained application
  2. Deploy your own runtime
  3. Use Linux Azure App Service
  4. Use Web Apps for Containers

See more details on how to do it in the link below: https://blogs.msdn.microsoft.com/webdev/2018/01/09/64-bit-asp-net-core-on-azure-app-service/

Credits to: Glenn Condron

Leash answered 14/1, 2018 at 18:44 Comment(0)
S
1

dotnet publish command generates a web.config file which is used by IIS to start dotnet process. In Kudu, in PATH environment variable dotnet.exe is from D:\Program Files (x86)\dotnet

Solution is to replace in this file after build

<aspNetCore processPath="dotnet" arguments=...

with:

<aspNetCore processPath="%ProgramFiles%\dotnet\dotnet" arguments=...
Symptomatic answered 4/9, 2019 at 7:48 Comment(0)
S
1

There are 4 requirements to your AppService running in 64bit

  1. Set the AppService to 64bit in Azure Portal (this makes the Webserver-Process run in 64bit)
  2. Make sure that your App is able to run on a 64bit platform (e.g. by setting the platform to x64 in your project file <PropertyGroup> <PlatformTarget>x64</PlatformTarget> </PropertyGroup>)
  3. ..and that's the one that took me the longest to figure out: Go to the Extensions blade of your AppService in Azure Portal and install the x64 extension for your .NET Version. So for me, at this point in time, I installed "ASP.NET Core 7.0 (x64) Runtime"
  4. Your AppService needs to run on a AppServicePlan of at least Basic tier (or higher of course)

In order to check if you succeeded you might want to include the result of Environment.Is64BitProcess somewhere in a log or something like it and see if you really are running in 64bit.

Sinful answered 12/6, 2023 at 7:33 Comment(0)
T
0

I was able to set my Windows App Service plan to 64 bit in the configuration tab on my WebApp application. Go to your web application under your app service plan. Settings --> Configuration --> Change 32 bit to 64 bit.

64-bit is a requirement for WebOptimizer to produce SCSS bundles on a Windows platform.

Trevortrevorr answered 8/6 at 0:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.