Skip to content

Crash on Linux due to DpiBootstrap static constructor #20544

Closed

Description

@HakanL

Current behavior

I was testing Uno 6.1.0-dev.167 to see if something I was tracking was fixed. Usually I can just build my application and run it on both Windows and Linux-arm64, just copying the full bin folder. With the upgrade to this test version I'm getting an exception right at the start, which I believe is related to this commit: f0c8d93 / PR #20443
Should there perhaps be a check if we're running on Windows? I tried to comment out UseWin32, but it still crashes (since there is a static constructor where this is called).

Exception:

Unhandled exception. System.TypeInitializationException: The type initializer for '<Module>' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'USER32.dll' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
/root/VSLinuxDbg/DMXCore100/runtimes/linux-arm64/native/USER32.dll.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.4/USER32.dll.so: cannot open shared object file: No such file or directory
/root/VSLinuxDbg/DMXCore100/USER32.dll.so: cannot open shared object file: No such file or directory
/root/VSLinuxDbg/DMXCore100/runtimes/linux-arm64/native/libUSER32.dll.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.4/libUSER32.dll.so: cannot open shared object file: No such file or directory
/root/VSLinuxDbg/DMXCore100/libUSER32.dll.so: cannot open shared object file: No such file or directory
/root/VSLinuxDbg/DMXCore100/runtimes/linux-arm64/native/USER32.dll: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.4/USER32.dll: cannot open shared object file: No such file or directory
/root/VSLinuxDbg/DMXCore100/USER32.dll: cannot open shared object file: No such file or directory
/root/VSLinuxDbg/DMXCore100/runtimes/linux-arm64/native/libUSER32.dll: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.4/libUSER32.dll: cannot open shared object file: No such file or directory
/root/VSLinuxDbg/DMXCore100/libUSER32.dll: cannot open shared object file: No such file or directory

   at Windows.Win32.PInvoke.<SetProcessDpiAwarenessContext>g__LocalExternFunction|240_0(DPI_AWARENESS_CONTEXT value)
   at Windows.Win32.PInvoke.<SetProcessDpiAwarenessContext>g__LocalExternFunction|240_0(DPI_AWARENESS_CONTEXT value)
   at Windows.Win32.PInvoke.SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT value)
   at DpiBootstrap.Init()
   at .cctor()
   --- End of inner exception stack trace ---
   at DMXCore.DMXCore100.Program.Main(String[] args)
Aborted

Startup code:

            var host = UnoPlatformHostBuilder.Create()
                .App(() => new App())
                .UseX11()
                .UseWin32()
                .Build();

Expected behavior

App should start

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

None

Environment

Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia

NuGet package version(s)

"Uno.Sdk": "6.1.0-dev.167"

Renderer

  • Skia
  • Native

Affected platforms

Desktop (X11)

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

Activity

  1. added
    kind/bug
    triage/untriaged
    difficulty/tbd
    on May 23, 2025
  2. changed the title [-]Crash on Linux when UseWin32 is in host builder (DpiBootstrap)[/-] [+]Crash on Linux due to DpiBootstrap static constructor[/+] on May 23, 2025
  3. self-assigned this
    on May 23, 2025
  4. HakanL commented on May 23, 2025

    @HakanL
    Author

    The last working version was 6.1.0-dev.152 (which unfortunately doesn't have the fix I was looking to test, #20506).

  5. jeromelaban commented on May 24, 2025

    @jeromelaban
    Member

    Thanks, this is an interesting issue.

    Our CI runs using Linux and is not failing this particular condition. We'll need to enhance our validations to catch this.

  6. Youssef1313 commented on May 25, 2025

    @Youssef1313
    Member

    @jeromelaban This is not caught in CI because SamplesApp avoids to load Win32 uno runtime assembly unless running on Windows:

    if (OperatingSystem.IsWindows())
    {
    void Build()
    {
    // This is in a separate method to avoid loading the win32 uno runtime assembly
    // This assumes that the runtime loads dependencies when entering the method.
    builder = builder
    .UseWin32(hostBuilder => hostBuilder.PreloadMediaPlayer(true));
    }
    Build();
    }

  7. HakanL commented on May 25, 2025

    @HakanL
    Author

    I tried that initially and it didn't work, it seems that at least for me, just having UseWin32() in the code causes the static constructor to be called (even if UseWin32 isn't called). Also, I used to be able to do UseWin32 even when running on Linux (just as I still have UseX11() when running in Windows).

  8. HakanL commented on May 27, 2025

    @HakanL
    Author

    I can confirm this is now working in Uno.Sdk version 6.1.0-dev.179.

  9. added theissue type on Jul 9, 2025
  10. github-actions commented on May 5, 2026

    @github-actions
    Contributor

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests.

  11. locked as resolved and limited conversation to collaborators on May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

difficulty/tbdkind/bugtriage/untriaged

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions