Repository navigation
fix(linux): only init DpiBootstrap on Windows - #20557
Conversation
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-20557/docs/index.html |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-20557/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-20557/docs/index.html |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-20557/wasm-skia-net9/index.html |
|
@ramezgerges I tried version 6.1.0-dev.177 and the issue is still there. I don't think just checking the result is enough, it fails to load the DLL which will throw an exception (I think @jeromelaban commented on that as well). I think you need to have a check for OS prior to attempting to make the call. I'm surprised your CI works, it crashes on my RPi arm64 system. |
|
@HakanL The file was moved to an assembly that is not loaded except on Windows. If it works in CI and on my side locally, it would be really surprising if it doesn't on your end. Maybe 177 doesn't the change. |
|
It's not included yet and will be in unoplatform/uno.templates#1528. You need track the builds from main using https://github.com/unoplatform/uno.templates/actions/workflows/ci.yml?query=branch%3Amain. There's a summary with the packages included in the SDK. |
|
@jeromelaban @ramezgerges Ah, sorry, my bad, I saw it in the |
|
@jeromelaban I know I've jumped the gun several times, I'm eager to try out the fixes, but it would be very helpful if your CI could post in the PR comments which Nuget dev build version where the merged PR would be available. |
I agree, we're working towards this, but not there yet. |
|
@ramezgerges I can confirm it's working now with Uno.Sdk version 6.1.0-dev.179. Again sorry for jumping the gun before and doubting the fix :) |
|
@Mergifyio backport release/stable/6.0 |
✅ Backports have been createdDetails
|
…6.0/pr-20557 fix(linux): only init DpiBootstrap on Windows (backport #20557)
…ash_linux fix(linux): only init DpiBootstrap on Windows
("Module initializers considered possibly harmful?")
This reverts commit 1003d8c.
Context: #20443
Context: #20544
Context: #20557
Context: unoplatform/uno.chefs#1709
[Module Initializers][0] are code that:
> …is executed at, or sometime before, first access to any static field
> or first invocation of any method defined in the module.
In a CoreCLR or MonoVM context, a module initializer is typically
executed shortly after the assembly is loaded.
In a NativeAOT context, module initializers are executed
[*at startup*][1]. All of them. All at once (sequentially).
This is fine…until you have a module initializer which assumes the
operating system that it's executing on.
Enter PR #20443, which introduced a module initializer which assumes
Windows.
This promptly broke Linux (#20544), the fix for which (#20557) was to
"only init DpiBootstrap on Windows".
Which works…so long as you have `DpiBootstrap` in a separate assembly
which is loaded on-demand.
Enter `src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent`,
which has a `.UseWin32()` invocation. When built for NativeAOT, the
`.UseWin32()` invocation (eventually) causes
`Uno.UI.Runtime.Skia.Win32.Support.dll` to be included in the app and
the `DpiBootstrap` module initializer executed during startup, which
promptly fails in a manner similar to #20544.
A workaround for this is to use a `#if` to exclude the `.UseWin32()`
invocation when building for non-Windows platforms. This allows the
trimmer to remove the reference to
`Uno.UI.Runtime.Skia.Win32.Support.dll`, avoiding its module
initializer; this is the approach taken in early drafts of
unoplatform/uno.chefs#1709.
Unfortunately, this doesn't "scale": we don't want every app to wrap
`.UseWin32()` invocations with a `#if`.
"Partially revert" part of #20443, returning to an earlier approach
wherein the DPI code is done within `Win32Host`, avoiding the use of
module initializers.
Test this scenario by updating `run-netcore-mobile-template-tests.ps1`
to allow running a binary after the build and before the clean.
Update `src/SolutionTemplate/5.6/uno56netcurrent` to support a new
`--exit` command-line argument; when provided, `App.OnLaunched()` will
call `Application.Exit()`, causing the app to exit. This allows us to
start the app and have it exit on CI. If it crashes, then the exit
code will be a non-zero value, e.g.
Executing: 5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/uno56netcurrent --exit
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'USER32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable:
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file)
dlopen(USER32.dll.dylib, 0x0001): tried: 'USER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSUSER32.dll.dylib' (no such file), '/usr/lib/USER32.dll.dylib' (no such file, not in dyld cache), 'USER32.dll.dylib' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file)
dlopen(libUSER32.dll.dylib, 0x0001): tried: 'libUSER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibUSER32.dll.dylib' (no such file), '/usr/lib/libUSER32.dll.dylib' (no such file, not in dyld cache), 'libUSER32.dll.dylib' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file)
dlopen(USER32.dll, 0x0001): tried: 'USER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OSUSER32.dll' (no such file), '/usr/lib/USER32.dll' (no such file, not in dyld cache), 'USER32.dll' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file)
dlopen(libUSER32.dll, 0x0001): tried: 'libUSER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibUSER32.dll' (no such file), '/usr/lib/libUSER32.dll' (no such file, not in dyld cache), 'libUSER32.dll' (no such file)
at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x46
at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x12c
at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
at Windows.Win32.PInvoke.<SetProcessDpiAwarenessContext>g__LocalExternFunction|267_0(DPI_AWARENESS_CONTEXT) + 0x22
at Windows.Win32.PInvoke.SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT) + 0x1b
at DpiBootstrap.Init() + 0x10
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunInitializers(TypeManagerHandle, ReadyToRunSectionType) + 0x45
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunModuleInitializers() + 0x37
…
Exception: /Users/runner/work/1/s/build/test-scripts/run-netcore-mobile-template-tests.ps1:13
Line |
13 | throw "Exit code must be zero."
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exit code must be zero.
[0]: https://github.com/dotnet/runtime/blob/2e85cbda5839dc36705686fc4a3d6b50f2cef5a9/docs/design/specs/Ecma-335-Augments.md#module-initializer
[1]: https://github.com/dotnet/runtime/blob/b1cb4c502f1eec66227a31e705934fb67fc091f0/src/coreclr/nativeaot/Common/src/Internal/Runtime/CompilerHelpers/tartupCodeHelpers.cs#L163-L169%5D
[2]: https://github.com/unoplatform/uno.chefs/blob/af0a0c928337688c5ed3e87c3389a1cfdad46933/Chefs/Platforms/Desktop/Program.cs#L15
("Module initializers considered possibly harmful?")
This reverts commit 1003d8c.
Context: #20443
Context: #20544
Context: #20557
Context: unoplatform/uno.chefs#1709
[Module Initializers][0] are code that:
> …is executed at, or sometime before, first access to any static field
> or first invocation of any method defined in the module.
In a CoreCLR or MonoVM context, a module initializer is typically
executed shortly after the assembly is loaded.
In a NativeAOT context, module initializers are executed
[*at startup*][1]. All of them. All at once (sequentially).
This is fine…until you have a module initializer which assumes the
operating system that it's executing on.
Enter PR #20443, which introduced a module initializer which assumes
Windows.
This promptly broke Linux (#20544), the fix for which (#20557) was to
"only init DpiBootstrap on Windows".
Which works…so long as you have `DpiBootstrap` in a separate assembly
which is loaded on-demand.
Enter `src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent`,
which has a `.UseWin32()` invocation. When built for NativeAOT, the
`.UseWin32()` invocation (eventually) causes
`Uno.UI.Runtime.Skia.Win32.Support.dll` to be included in the app and
the `DpiBootstrap` module initializer executed during startup, which
promptly fails in a manner similar to #20544.
A workaround for this is to use a `#if` to exclude the `.UseWin32()`
invocation when building for non-Windows platforms. This allows the
trimmer to remove the reference to
`Uno.UI.Runtime.Skia.Win32.Support.dll`, avoiding its module
initializer; this is the approach taken in early drafts of
unoplatform/uno.chefs#1709.
Unfortunately, this doesn't "scale": we don't want every app to wrap
`.UseWin32()` invocations with a `#if`.
"Partially revert" part of #20443, returning to an earlier approach
wherein the DPI code is done within `Win32Host`, avoiding the use of
module initializers.
Test this scenario by updating `run-netcore-mobile-template-tests.ps1`
to allow running a binary after the build and before the clean.
Update `src/SolutionTemplate/5.6/uno56netcurrent` to support a new
`--exit` command-line argument; when provided, `App.OnLaunched()` will
call `Application.Exit()`, causing the app to exit. This allows us to
start the app and have it exit on CI. If it crashes, then the exit
code will be a non-zero value, e.g.
Executing: 5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/uno56netcurrent --exit
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'USER32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable:
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file)
dlopen(USER32.dll.dylib, 0x0001): tried: 'USER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSUSER32.dll.dylib' (no such file), '/usr/lib/USER32.dll.dylib' (no such file, not in dyld cache), 'USER32.dll.dylib' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file)
dlopen(libUSER32.dll.dylib, 0x0001): tried: 'libUSER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibUSER32.dll.dylib' (no such file), '/usr/lib/libUSER32.dll.dylib' (no such file, not in dyld cache), 'libUSER32.dll.dylib' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file)
dlopen(USER32.dll, 0x0001): tried: 'USER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OSUSER32.dll' (no such file), '/usr/lib/USER32.dll' (no such file, not in dyld cache), 'USER32.dll' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file)
dlopen(libUSER32.dll, 0x0001): tried: 'libUSER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibUSER32.dll' (no such file), '/usr/lib/libUSER32.dll' (no such file, not in dyld cache), 'libUSER32.dll' (no such file)
at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x46
at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x12c
at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
at Windows.Win32.PInvoke.<SetProcessDpiAwarenessContext>g__LocalExternFunction|267_0(DPI_AWARENESS_CONTEXT) + 0x22
at Windows.Win32.PInvoke.SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT) + 0x1b
at DpiBootstrap.Init() + 0x10
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunInitializers(TypeManagerHandle, ReadyToRunSectionType) + 0x45
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunModuleInitializers() + 0x37
…
Exception: /Users/runner/work/1/s/build/test-scripts/run-netcore-mobile-template-tests.ps1:13
Line |
13 | throw "Exit code must be zero."
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exit code must be zero.
[0]: https://github.com/dotnet/runtime/blob/2e85cbda5839dc36705686fc4a3d6b50f2cef5a9/docs/design/specs/Ecma-335-Augments.md#module-initializer
[1]: https://github.com/dotnet/runtime/blob/b1cb4c502f1eec66227a31e705934fb67fc091f0/src/coreclr/nativeaot/Common/src/Internal/Runtime/CompilerHelpers/tartupCodeHelpers.cs#L163-L169%5D
[2]: https://github.com/unoplatform/uno.chefs/blob/af0a0c928337688c5ed3e87c3389a1cfdad46933/Chefs/Platforms/Desktop/Program.cs#L15
("Module initializers considered problematic?")
Context: #20443
Context: #20544
Context: #20557
Context: unoplatform/uno.chefs#1709
[Module Initializers][0] are code that:
> …is executed at, or sometime before, first access to any static field
> or first invocation of any method defined in the module.
In a CoreCLR or MonoVM context, a module initializer is typically
executed shortly after the assembly is loaded.
In a NativeAOT context, module initializers are executed
[*at startup*][1]. All of them. All at once (sequentially).
This is fine…until you have a module initializer which assumes the
operating system that it's executing on.
Enter PR #20443, which introduced a module initializer which assumes
Windows.
This promptly broke Linux (#20544), the fix for which (#20557) was to
"only init DpiBootstrap on Windows".
Which works…so long as you have `DpiBootstrap` in a separate assembly
which is loaded on-demand.
Enter `src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent`,
which has a `.UseWin32()` invocation. When run under NativeAOT:
dotnet publish src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/*.csproj \
-c Release -r osx-x64 -p:UnoTargetFrameworkOverride=net10.0-desktop -f net10.0-desktop \
-p:SelfContained=true -p:PublishAot=true -bl
src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/uno56netcurrent
the `.UseWin32()` invocation (eventually) causes
`Uno.UI.Runtime.Skia.Win32.Support.dll` to be included in the app and
the `DpiBootstrap` module initializer executed during startup, which
promptly fails in a manner similar to #20544:
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'USER32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable:
…
A workaround for this is to use a `#if` to exclude the `.UseWin32()`
invocation when building for non-Windows platforms. This allows the
trimmer to remove the reference to
`Uno.UI.Runtime.Skia.Win32.Support.dll`, avoiding its module
initializer; this is the approach taken in early drafts of
unoplatform/uno.chefs#1709.
Unfortunately, this doesn't "scale": we don't want every app to wrap
`.UseWin32()` invocations with a `#if`.
Update `DpiBootstrap` to wrap the `SetProcessDpiAwarenessContext()`
call in a `if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))`
block[^0]. This ensures the code is only run on Windows, and should
avoid the crash on non-Windows platforms.
Test this scenario by updating `run-netcore-mobile-template-tests.ps1`
to allow running a binary after the build and before the clean.
Update `src/SolutionTemplate/5.6/uno56netcurrent` to support a new
`--exit` command-line argument; when provided, `App.OnLaunched()` will
call `Application.Exit()`, causing the app to exit. This allows us to
start the app and have it exit on CI. If it crashes, then the exit
code will be a non-zero value, e.g.
Executing: 5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/uno56netcurrent --exit
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'USER32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable:
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file)
dlopen(USER32.dll.dylib, 0x0001): tried: 'USER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSUSER32.dll.dylib' (no such file), '/usr/lib/USER32.dll.dylib' (no such file, not in dyld cache), 'USER32.dll.dylib' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file)
dlopen(libUSER32.dll.dylib, 0x0001): tried: 'libUSER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibUSER32.dll.dylib' (no such file), '/usr/lib/libUSER32.dll.dylib' (no such file, not in dyld cache), 'libUSER32.dll.dylib' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file)
dlopen(USER32.dll, 0x0001): tried: 'USER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OSUSER32.dll' (no such file), '/usr/lib/USER32.dll' (no such file, not in dyld cache), 'USER32.dll' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file)
dlopen(libUSER32.dll, 0x0001): tried: 'libUSER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibUSER32.dll' (no such file), '/usr/lib/libUSER32.dll' (no such file, not in dyld cache), 'libUSER32.dll' (no such file)
at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x46
at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x12c
at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
at Windows.Win32.PInvoke.<SetProcessDpiAwarenessContext>g__LocalExternFunction|267_0(DPI_AWARENESS_CONTEXT) + 0x22
at Windows.Win32.PInvoke.SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT) + 0x1b
at DpiBootstrap.Init() + 0x10
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunInitializers(TypeManagerHandle, ReadyToRunSectionType) + 0x45
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunModuleInitializers() + 0x37
…
Exception: /Users/runner/work/1/s/build/test-scripts/run-netcore-mobile-template-tests.ps1:13
Line |
13 | throw "Exit code must be zero."
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exit code must be zero.
[0]: https://github.com/dotnet/runtime/blob/2e85cbda5839dc36705686fc4a3d6b50f2cef5a9/docs/design/specs/Ecma-335-Augments.md#module-initializer
[1]: https://github.com/dotnet/runtime/blob/b1cb4c502f1eec66227a31e705934fb67fc091f0/src/coreclr/nativeaot/Common/src/Internal/Runtime/CompilerHelpers/tartupCodeHelpers.cs#L163-L169%5D
[2]: https://github.com/unoplatform/uno.chefs/blob/af0a0c928337688c5ed3e87c3389a1cfdad46933/Chefs/Platforms/Desktop/Program.cs#L15
[3]: https://github.com/unoplatform/uno.licensing/tree/90428261b08e4115e9ce1f08d2799e2451340491/src/Uno.Settings
[4]: https://github.com/unoplatform/uno.licensing/blob/90428261b08e4115e9ce1f08d2799e2451340491/src/Uno.Settings/Uno.Settings/Platforms/Desktop/Program.cs#L17-L23
[^0]: An alternate approach was to remove the module initializer
completely, and instead rely on `Win32Host` to init DPI.
The problem with this approach is the [Uno.Settings app][3]:
there is a requirement that it be launchable as
`dotnet Uno.Settings.dll`, i.e. outside of an "app manifest"
environment. Additionally, DPI must be set *before* the Windows
message loop is created. Given that a message loop is possibly
created [before the Uno Platform Host is created][4], the only
reliable mechanism to ensure DPI is set properly that doesn't
require a code change is via a module initializer.
("Module initializers considered problematic?")
Context: #20443
Context: #20544
Context: #20557
Context: unoplatform/uno.chefs#1709
[Module Initializers][0] are code that:
> …is executed at, or sometime before, first access to any static field
> or first invocation of any method defined in the module.
In a CoreCLR or MonoVM context, a module initializer is typically
executed shortly after the assembly is loaded.
In a NativeAOT context, module initializers are executed
[*at startup*][1]. All of them. All at once (sequentially).
This is fine…until you have a module initializer which assumes the
operating system that it's executing on.
Enter PR #20443, which introduced a module initializer which assumes
Windows.
This promptly broke Linux (#20544), the fix for which (#20557) was to
"only init DpiBootstrap on Windows".
Which works…so long as you have `DpiBootstrap` in a separate assembly
which is loaded on-demand.
Enter `src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent`,
which has a `.UseWin32()` invocation. When run under NativeAOT:
dotnet publish src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/*.csproj \
-c Release -r osx-x64 -p:UnoTargetFrameworkOverride=net10.0-desktop -f net10.0-desktop \
-p:SelfContained=true -p:PublishAot=true -bl
src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/uno56netcurrent
the `.UseWin32()` invocation (eventually) causes
`Uno.UI.Runtime.Skia.Win32.Support.dll` to be included in the app and
the `DpiBootstrap` module initializer executed during startup, which
promptly fails in a manner similar to #20544:
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'USER32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable:
…
A workaround for this is to use a `#if` to exclude the `.UseWin32()`
invocation when building for non-Windows platforms. This allows the
trimmer to remove the reference to
`Uno.UI.Runtime.Skia.Win32.Support.dll`, avoiding its module
initializer; this is the approach taken in early drafts of
unoplatform/uno.chefs#1709.
Unfortunately, this doesn't "scale": we don't want every app to wrap
`.UseWin32()` invocations with a `#if`.
Update `DpiBootstrap` to wrap the `SetProcessDpiAwarenessContext()`
call in a `if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))`
block[^0]. This ensures the code is only run on Windows, and should
avoid the crash on non-Windows platforms.
Test this scenario by updating `run-netcore-mobile-template-tests.ps1`
to allow running a binary after the build and before the clean.
Update `src/SolutionTemplate/5.6/uno56netcurrent` to support a new
`--exit` command-line argument; when provided, `App.OnLaunched()` will
call `Application.Exit()`, causing the app to exit. This allows us to
start the app and have it exit on CI. If it crashes, then the exit
code will be a non-zero value, e.g.
Executing: 5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/uno56netcurrent --exit
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'USER32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable:
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll.dylib' (no such file)
dlopen(USER32.dll.dylib, 0x0001): tried: 'USER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSUSER32.dll.dylib' (no such file), '/usr/lib/USER32.dll.dylib' (no such file, not in dyld cache), 'USER32.dll.dylib' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll.dylib' (no such file)
dlopen(libUSER32.dll.dylib, 0x0001): tried: 'libUSER32.dll.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibUSER32.dll.dylib' (no such file), '/usr/lib/libUSER32.dll.dylib' (no such file, not in dyld cache), 'libUSER32.dll.dylib' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/USER32.dll' (no such file)
dlopen(USER32.dll, 0x0001): tried: 'USER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OSUSER32.dll' (no such file), '/usr/lib/USER32.dll' (no such file, not in dyld cache), 'USER32.dll' (no such file)
dlopen(/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll, 0x0001): tried: '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file), '/Users/runner/work/1/s/src/SolutionTemplate/5.6/uno56netcurrent/uno56netcurrent/bin/Release/net10.0-desktop/osx-x64/publish/libUSER32.dll' (no such file)
dlopen(libUSER32.dll, 0x0001): tried: 'libUSER32.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibUSER32.dll' (no such file), '/usr/lib/libUSER32.dll' (no such file, not in dyld cache), 'libUSER32.dll' (no such file)
at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x46
at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x12c
at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
at Windows.Win32.PInvoke.<SetProcessDpiAwarenessContext>g__LocalExternFunction|267_0(DPI_AWARENESS_CONTEXT) + 0x22
at Windows.Win32.PInvoke.SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT) + 0x1b
at DpiBootstrap.Init() + 0x10
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunInitializers(TypeManagerHandle, ReadyToRunSectionType) + 0x45
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunModuleInitializers() + 0x37
…
Exception: /Users/runner/work/1/s/build/test-scripts/run-netcore-mobile-template-tests.ps1:13
Line |
13 | throw "Exit code must be zero."
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exit code must be zero.
[0]: https://github.com/dotnet/runtime/blob/2e85cbda5839dc36705686fc4a3d6b50f2cef5a9/docs/design/specs/Ecma-335-Augments.md#module-initializer
[1]: https://github.com/dotnet/runtime/blob/b1cb4c502f1eec66227a31e705934fb67fc091f0/src/coreclr/nativeaot/Common/src/Internal/Runtime/CompilerHelpers/tartupCodeHelpers.cs#L163-L169%5D
[2]: https://github.com/unoplatform/uno.chefs/blob/af0a0c928337688c5ed3e87c3389a1cfdad46933/Chefs/Platforms/Desktop/Program.cs#L15
[3]: https://github.com/unoplatform/uno.licensing/tree/90428261b08e4115e9ce1f08d2799e2451340491/src/Uno.Settings
[4]: https://github.com/unoplatform/uno.licensing/blob/90428261b08e4115e9ce1f08d2799e2451340491/src/Uno.Settings/Uno.Settings/Platforms/Desktop/Program.cs#L17-L23
[^0]: An alternate approach was to remove the module initializer
completely, and instead rely on `Win32Host` to init DPI.
The problem with this approach is the [Uno.Settings app][3]:
there is a requirement that it be launchable as
`dotnet Uno.Settings.dll`, i.e. outside of an "app manifest"
environment. Additionally, DPI must be set *before* the Windows
message loop is created. Given that a message loop is possibly
created [before the Uno Platform Host is created][4], the only
reliable mechanism to ensure DPI is set properly that doesn't
require a code change is via a module initializer.
GitHub Issue (If applicable): closes #20544
PR Type
What kind of change does this PR introduce?
What is the current behavior?
What is the new behavior?
PR Checklist
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.Other information
Internal Issue (If applicable):