Publishing .NET 6 application as Arm64

Nicke Manarin 1 Reputation point
2022-04-15T23:00:41.127+00:00

I had an app that was using .NET Framework 4.8 and I was publishing it as AnyCPU.
Since I migrated to .NET 6, I now have to export the app as x64/arm64.

My issue is that users with arm64 machines are not able to run the arm64 app variant.
They get this exception when running:

An attempt was made to load a program with an incorrect format. (0x8007000B)  
System.BadImageFormatException  
 at MS.Win32.PresentationCore.UnsafeNativeMethods.MilCoreApi.RenderOptions_ForceSoftwareRenderingModeForProcess(Boolean fForce)  
 at System.Windows.Media.RenderOptions.set_ProcessRenderMode(RenderMode value)  
 at Myapp.App.App_Startup(Object sender, StartupEventArgs e) in App.xaml.cs:line 156  
 at System.Windows.Application.OnStartup(StartupEventArgs e)  
 at System.Windows.Application.<.ctor>b__1_0(Object unused)  
 at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)  
 at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)  

I checked the line that was triggering the issue and found this:

RenderOptions.ProcessRenderMode = MyApp.Util.Settings.All.DisableHardwareAcceleration ? RenderMode.SoftwareOnly : RenderMode.Default;  

The app tries to get the settings, calling the settings class from MyApp.Util library.

-----------------------------

This error doesn't make much sense, because the app is being exported as win-arm64 using dotnet.exe publish.

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
  <PropertyGroup>  
    <Configuration>Release</Configuration>  
    <Platform>ARM64</Platform>  
    <PublishDir>bin\Publish\Full\ARM64</PublishDir>  
    <PublishProtocol>FileSystem</PublishProtocol>  
    <TargetFramework>net6.0-windows</TargetFramework>  
    <RuntimeIdentifier>win-arm64</RuntimeIdentifier>  
    <SelfContained>true</SelfContained>  
    <PublishSingleFile>False</PublishSingleFile>  
    <PublishReadyToRun>False</PublishReadyToRun>  
  </PropertyGroup>  
</Project>  

I went and checked the libraries generated using a dependency walker and found that all the DLL's related to the app were generated as i386 instead of ARM64.
Also, some system DLL's were exported like that too.

193507-image.png

What's going on here?
How can I detect which library is causing the issue?
Since I don't have an arm64 machine, how can I ask for debugging details from the user?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,681 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,306 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2022-04-17T22:38:00.81+00:00

    SharpDx has not been maintained since 2019 so I dont think it supports arm.