How to change Azure App Service to 64-bit

18,468

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

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=...
Share:
18,468
ajbeaven
Author by

ajbeaven

Updated on June 07, 2022

Comments

  • ajbeaven
    ajbeaven almost 2 years

    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.