Search code examples
c#maui.net-mauimaui-windows

How to build x86 (32-bit) version of .NET MAUI App?


We have a legacy 32-bit C++ dll that we want to use in the .NET MAUI app. The Android version (.so) of this library is working fine. But while trying to load the dll on Windows it fails with following error.

System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)

64-bit app and 32-bit dll can be solved using WCF or Remoting, but these solutions are not workable for our scenario.

We need to build the .NET MAUI app as 32-bit x86 app, but we haven't found any documentation regarding same.

Tried adding the following by manually editing the csproj file -

<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
    <RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>

But it broke the build with an seemingly unrelated error error NETSDK1135: SupportedOSPlatformVersion 10.0.19041.0 cannot be higher than TargetPlatformVersion 10.0.17763.0.

Any directions or samples available anywhere?


Solution

  • Pass -r win10-x86 to the publish commandline to set the RID to 32 bit Windows 10:

    dotnet publish -f net6.0-windows10.0.19041.0 -c Release -r win10-x86