How can I build a self-contained C# WinUI application from within a Windows Docker container (`XamlCompiler.exe` exits with code `-1073741515`)? – C#

by
Ali Hasan
boot2docker c# windows-container winui-3

The Problem:

I’m trying to build a self-contained C# WinUI application from within a Windows Docker container using Microsoft’s provided sample code. However, the build fails with the error code -1073741515, specifically in the XamlCompiler.exe tool, during the project’s restoration phase. The error message indicates that the tool exited with this error code, but no further details or solutions are provided. The build command has been executed on the host machine using dotnet publish, and the error occurs during the compilation of the XAML markup. I need help understanding what this error means and how I can resolve it to successfully build and run my WinUI application inside the Docker container.

The Solutions:

Solution 1: Use a WindowsServerCore based image and set `/p:UseXamlCompilerExecutable=false`

  1. Use a WindowsServerCore based image like mcr.microsoft.com/dotnet/sdk:8.0-windowsservercore-ltsc2022.

  2. Add /p:UseXamlCompilerExecutable=false to the dotnet publish command.

    docker run `
      --platform windows `
      --rm `
      --interactive `
      --tty `
      --mount "type=bind,source=$PWD,target=C:\application" `
      --workdir /application `
      mcr.microsoft.com/dotnet/sdk:8.0-windowsservercore-ltsc2022 `
      dotnet publish --configuration Release /p:UseXamlCompilerExecutable=false
    

Q&A

What’s the meaning of error -1073741515 when running XamlCompiler.exe in a Docker container?

This error code suggests the absence of a full .NET Framework 4.7.x installation on the OS.

Why does XamlCompiler.exe need a full .NET Framework 4.7.x installation?

It relies on an executable from the .NET Framework 4.7.x, which is absent in minimal images like Nano Server.

How to resolve this issue?

Use a Docker image based on Windows Server Core, which includes the full .NET Framework.