Skip to content

Add DPI awareness - #20443

Merged
carldebilly merged 2 commits into
masterfrom
dev/cdb/bugs/force-process-dpiawareness
May 22, 2025
Merged

carldebilly merged 2 commits into
masterfrom
dev/cdb/bugs/force-process-dpiawareness

Conversation

@carldebilly

Copy link
Copy Markdown
Member

GitHub Issue (If applicable): closes https://github.com/unoplatform/uno.hotdesign/issues/4139

Bugfix

What is the new behavior?

  • Introduced SetProcessDpiAwareness() to address DPI scaling issues when not defined in the process manifest (when started from dotnet run)

PR Checklist

Please check if your PR fulfills the following requirements:

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses DPI scaling issues for processes launched via the .NET CLI by adding proper DPI awareness and improving related XAML method naming. Key changes include:

  • Introducing a new method SetProcessDpiAwareness() to set per-monitor DPI awareness.
  • Logging an error if setting DPI awareness fails.
  • Updating NativeMethods.txt to include the new SetProcessDpiAwarenessContext API.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Uno.UI.Runtime.Skia.Win32/Win32Host.cs Added SetProcessDpiAwareness() method and its invocation in the initialization routine.
src/Uno.UI.Runtime.Skia.Win32.Support/NativeMethods.txt Documented the SetProcessDpiAwarenessContext API for native interop.
Comments suppressed due to low confidence (1)

src/Uno.UI.Runtime.Skia.Win32.Support/NativeMethods.txt:196

  • [nitpick] Ensure that the inclusion of SetProcessDpiAwarenessContext in this file is complemented by updates in the corresponding documentation, so its purpose and usage are clearly communicated.
SetProcessDpiAwarenessContext

@carldebilly carldebilly changed the title Add DPI awareness and improve XAML method naming Add DPI awareness May 16, 2025
@carldebilly

Copy link
Copy Markdown
Member Author

@MartinZikmund @dr1rrb Please review this. It solve the problem when the process is started using dotnet run because there's no RT_MANIFEST in this executable declaring a process-wide dpi awareness.

This change MAY break uno island, so maybe there's a better approach to it. Since the SetThreadDpiAwarenessContext() seems to not apply on pointers (they are coming from a different thread?)

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 165973 found UI Test snapshots differences: android-28-net8: 20, android-28-net8-Snap: 41, ios: 4, ios-Snap: 35, skia-linux-screenshots: 69, skia-windows-screenshots: 168, wasm: 47, wasm-automated-net9.0-WinUI-Benchmarks-automated: 0, wasm-automated-net9.0-WinUI-Default-automated: 15, wasm-automated-net9.0-WinUI-RuntimeTests-0: 0, wasm-automated-net9.0-WinUI-RuntimeTests-1: 0, wasm-automated-net9.0-WinUI-RuntimeTests-2: 0

Details
  • android-28-net8: 20 changed over 824

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Detereminate_ProgressRing_Validation50_[#FF0000_#008000_#008000_#FF0000]_Progress-Ring-Value-50
    • FlyoutTest_When_NoOverlayInputPassThroughElement_Then_DontPassThrough_woOff_UITests_Shared_Windows_UI_Xaml_Controls_Flyout_Flyout_OverlayInputPassThroughElement
    • Detereminate_ProgressRing_Validation25_[#FF0000_#008000_#FF0000_#FF0000]_Progress-Ring-Value-25
    • Detereminate_ProgressRing_Validation75_[#FF0000_#008000_#008000_#008000]_Progress-Ring-Value-75
    • ListView_SelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • ProgressRing_IsEnabled_Running_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • SequentialAnimations_SamplesApp_Windows_UI_Xaml_Media_Animation_SequentialAnimationsPage
    • When_Parent_PointerMoved_After_drag_on_ScrollViewer_-_touch
    • When_SingleSelectionWithItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_SingleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_BitmapIcon_Generic_Changed
    • When_BitmapIcon_Generic_Initial
    • When_BitmapIcon_Generic_UITests_Shared_Windows_UI_Xaml_Controls_BitmapIconTests_BitmapIcon_Generic
    • UpDownEnabledTest_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
    • ProgressRing_Visibility_Collapsed_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • When_ExtendedSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_NoSelectionWithItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_Parent_PointerMoved_After_drag_on_non-scrolling_ScrollViewer
    • Button_IsOpacity_Validation_Uno_UI_Samples_Content_UITests_ButtonTestsControl_Button_Opacity_Automated
    • DecimalFormatterTest_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
  • android-28-net8-Snap: 41 changed over 1067

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • MediaPlayerElement_Sources_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Sources
    • MediaPlayerElement_Using_3gp_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_3gp_Extension
    • MediaPlayerElement_Using_mp3_Audio_only_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Mp3_Extension
    • MediaPlayerElement_Using_ogg_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Ogg_Extension
    • SwipeControl_MUXControlsTestApp_SwipeControlPage2_MUXControlsTestApp_SwipeControlPage2
    • Gesture_Recognizer_Pointer_Events_test_bench_UITests_Shared_Windows_UI_Input_GestureRecognizer_PointersEvents
    • Buttons_UITests_Microsoft_UI_Xaml_Controls_RadioButtonsTests_RadioButtonsPage_UITests_Microsoft_UI_Xaml_Controls_RadioButtonsTests_RadioButtonsPage
    • MediaPlayerElement_Mini_player_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Minimal
    • Scrolling_MUXControlsTestApp_ScrollViewDynamicPage_MUXControlsTestApp_ScrollViewDynamicPage
    • Scrolling_MUXControlsTestApp_ScrollViewKeyboardAndGamepadNavigationPage_MUXControlsTestApp_ScrollViewKeyboardAndGamepadNavigationPage
    • Image_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_Icons_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_Icons
    • MUX_NumberBox_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
    • RatingControl_UITests_Microsoft_UI_Xaml_Controls_RatingControlTests_RatingControlPage_UITests_Microsoft_UI_Xaml_Controls_RatingControlTests_RatingControlPage
    • NavigationView_MUXControlsTestApp_NavigationViewCustomThemeResourcesPage_MUXControlsTestApp_NavigationViewCustomThemeResourcesPage
    • TeachingTip_UITests_Microsoft_UI_Xaml_Controls_TeachingTipTests_TeachingTipPage_UITests_Microsoft_UI_Xaml_Controls_TeachingTipTests_TeachingTipPage
    • TextBlock_UITests_Shared_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_Layout_UITests_Shared_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_Layout
    • ListView_ListViewSelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • NavigationView_MUXControlsTestApp_NavigationViewRS4Page_MUXControlsTestApp_NavigationViewRS4Page
    • NavigationView_MUXControlsTestApp_NavigationViewTopNavOnlyPage_MUXControlsTestApp_NavigationViewTopNavOnlyPage
    • NavigationView_MUXControlsTestApp_NavigationViewTopNavPage_MUXControlsTestApp_NavigationViewTopNavPage
  • ios: 4 changed over 255

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Check_ListView_Swallows_Measure_UITests_Shared_Windows_UI_Xaml_Controls_ListView_ListView_With_ListViews_Count_Measure
    • TextBox_UpdatedBinding_On_OneWay_Mode_UITests_Windows_UI_Xaml_Controls_TextBox_TextBox_Bindings
    • ProgressRing_Visibility_Collapsed_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • ProgressRing_IsEnabled_Running_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
  • ios-Snap: 35 changed over 984

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Icons_UITests_Shared_Windows_UI_Xaml_Controls_BitmapIconTests_BitmapIcon_Foreground_UITests_Shared_Windows_UI_Xaml_Controls_BitmapIconTests_BitmapIcon_Foreground
    • Brushes_EllipsemaskingEllipseGrid_Uno_UI_Samples_UITests_ImageBrushTestControl_EllipsemaskingEllipseGrid
    • Brushes_BorderImageBrush_Uno_UI_Samples_UITests_ImageBrushTestControl_BorderImageBrush
    • Brushes_ImageBrushWithScaleTransform_Uno_UI_Samples_UITests_ImageBrushTestControl_ImageBrushWithScaleTransform
    • Focus_UITests_Windows_UI_Xaml_FocusTests_Focus_FocusCycle_UITests_Windows_UI_Xaml_FocusTests_Focus_FocusCycle
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Wider_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Wider
    • MediaPlayerElement_Sources_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Sources
    • SwipeControl_MUXControlsTestApp_SwipeControlPage2_MUXControlsTestApp_SwipeControlPage2
    • Brushes_ImageBrushWithCompositeTransform_Uno_UI_Samples_UITests_ImageBrushTestControl_ImageBrushWithCompositeTransform
    • Brushes_RectangleStretchFill_Uno_UI_Samples_UITests_ImageBrushTestControl_RectangleStretchFill
    • Scrolling_MUXControlsTestApp_ScrollViewDynamicPage_MUXControlsTestApp_ScrollViewDynamicPage
    • UIElement_TransformToVisual_Simple_UITests_Shared_Windows_UI_Xaml_UIElementTests_TransformToVisual_Simple
    • Default_SamplesApp_Wasm_Windows_UI_Xaml_Controls_ListView_ListView_IsSelected_SamplesApp_Wasm_Windows_UI_Xaml_Controls_ListView_ListView_IsSelected
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Bigger_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Bigger
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Equal_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Equal
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Smaller_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Smaller
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Taller_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Taller
    • WebView_UITests_Microsoft_UI_Xaml_Controls_WebView2Tests_WebView2_NavigationProperties_UITests_Microsoft_UI_Xaml_Controls_WebView2Tests_WebView2_NavigationProperties
    • GridView_GenericApp_Views_Samples_Shared_Content_UITests_GridViewGrouped_GenericApp_Views_Samples_Shared_Content_UITests_GridViewGrouped
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Uno_UI_Samples_UITests_Image_Image_Stretch
  • skia-linux-screenshots: 69 changed over 2246

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • ImageBrushAlignmentXY.png-dark
    • ImageBrushAlignmentXY.png
    • ButtonClippingTestsControl.png-dark
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Ellipse.png-dark
    • Ellipse.png
    • DragDrop_TestPage.png-dark
    • DragDrop_TestPage.png
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • Buttons.png-dark
  • skia-windows-screenshots: 168 changed over 2246

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ApplicationViewSizing.png
    • BenchmarkDotNet.png-dark
    • CommandBar_BackButtonTitle.png-dark
    • CommandBar_BackButtonTitle.png
    • CommandBar_Background.png-dark
    • CommandBar_Background.png
    • AnimatedIconPage.png
    • AppWindowPresenters.png
    • ClipboardTests.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • AppWindowClosing.png
    • AppWindowClosing.png-dark
    • AppWindowPresenters.png-dark
    • BasicEnability.png-dark
    • Buttons.png
    • ButtonClippingTestsControl.png-dark
    • ComboBox_ItemDataContext.png-dark
    • ComboBox_ItemDataContext.png
    • Examples.png
  • wasm: 47 changed over 1051

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • GenericApp.Views.Samples.Shared.Content.UITests.GridViewMultipleSelectionMode
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewHeaderFooter_ImplicitlyBinded
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Windows_UI_Xaml_Controls.CommandBar.BackButtonTitle.CommandBar_Frame
    • UITests.Windows_UI_Xaml_Controls.ImageTests.SvgImageSource_FromMsAppData
    • UITests.Windows_UI_Xaml_Controls.ImageTests.SvgImageSource_FromStream
    • Uno.UI.Samples.Content.UITests.ButtonTestsControl.RadioButton_Multiple_Unnamed_Groups
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ComboBox.ComboBox_Corners
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListView_Expandable_Item_Large
    • UITests.Windows_UI_Xaml_Controls.ListView.ListViewItem_IsEnabled
    • UITests.Windows_UI_Xaml_Controls.ListView.ListView_DuplicateItem
    • UITests.Windows_UI_Xaml_Media.AcrylicBrushTests.BasicAcrylicBrushTest
    • Uno.UI.Samples.Content.UITests.ButtonTestsControl.CheckBox_Button
    • UITests.Shared.Windows_UI_Input.PointersTests.EventsSequences
    • UITests.Windows_UI_Xaml.FocusTests.Focus_FocusState
    • UITests.Windows_UI_Xaml_Controls.Repeater.ItemsRepeater_Nested
    • Uno.UI.Samples.Content.UITests.GridView.GridViewVariableItemHeight
    • UITests.Shared.Windows_UI_Xaml_Controls.Button.Overlapped_Buttons
  • wasm-automated-net9.0-WinUI-Benchmarks-automated: 0 changed over 1

  • wasm-automated-net9.0-WinUI-Default-automated: 15 changed over 876

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Default_StrokeThickness_MyPolygon
    • SequentialAnimations_SamplesApp_Windows_UI_Xaml_Media_Animation_SequentialAnimationsPage
    • When_Padding_Is_Changed_Then_Cache_Is_Missed_UITests_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_MeasureCache
    • When_SingleSelectionWithItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_SingleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • Default_StrokeThickness_MyPath
    • When_MaxLines_Then_AlignmentPositionIsCorrect_Uno_UI_Samples_Content_UITests_TextBlockControl_SimpleText_MaxLines_Two_With_Wrap
    • Default_StrokeThickness_MyLine
    • ListView_SelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • Default_StrokeThickness_MyPolyline
    • TestProgressRing_InitialState_UITests_Microsoft_UI_Xaml_Controls_ProgressRing_WinUIProgressRing_Features
    • Default_StrokeThickness_MyEllipse
    • When_TextTrimming_Is_Set_Then_Ellipsis_Is_Used_UITests_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_TextTrimming
    • When_NoSelection_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_TransformToVisual_ScrollViewer_UITests_Shared_Windows_UI_Xaml_UIElementTests_TransformToVisual_ScrollViewer
  • wasm-automated-net9.0-WinUI-RuntimeTests-0: 0 changed over 1

  • wasm-automated-net9.0-WinUI-RuntimeTests-1: 0 changed over 1

  • wasm-automated-net9.0-WinUI-RuntimeTests-2: 0 changed over 1

@MartinZikmund
MartinZikmund requested a review from ramezgerges May 19, 2025 09:54
@MartinZikmund

Copy link
Copy Markdown
Member

Seems good, but will also let @ramezgerges chime in 👍

@nickrandolph nickrandolph added kind/bug Something isn't working and removed kind/documentation labels May 20, 2025
Introduced SetProcessDpiAwareness() to address DPI scaling issues when running from dotnet CLI.
Move DPI awareness setup to a dedicated `DpiBootstrap` class using a module initializer for improved clarity and reuse. This ensures the correct DPI context is applied before any window initialization, replacing redundant logic in `Win32Host`.
@carldebilly
carldebilly force-pushed the dev/cdb/bugs/force-process-dpiawareness branch from d728cc8 to 1003d8c Compare May 21, 2025 15:04
@unodevops

Copy link
Copy Markdown
Contributor

@carldebilly
carldebilly marked this pull request as ready for review May 21, 2025 16:03
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 166322 has failed on Uno.UI - CI.

@jeromelaban

Copy link
Copy Markdown
Member

@Mergifyio backport release/stable/6.0

@mergify

mergify Bot commented May 21, 2025 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.0

✅ Backports have been created

Details

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 166322 found UI Test snapshots differences: android-28-net8: 26, android-28-net8-Snap: 51, ios: 4, ios-Snap: 49, skia-linux-screenshots: 61, skia-windows-screenshots: 61, wasm: 54, wasm-automated-net9.0-WinUI-Benchmarks-automated: 0, wasm-automated-net9.0-WinUI-Default-automated: 14, wasm-automated-net9.0-WinUI-RuntimeTests-0: 0, wasm-automated-net9.0-WinUI-RuntimeTests-1: 1, wasm-automated-net9.0-WinUI-RuntimeTests-2: 1

Details
  • android-28-net8: 26 changed over 824

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Detereminate_ProgressRing_Validation25_[#FF0000_#008000_#FF0000_#FF0000]_Progress-Ring-Value-25
    • Detereminate_ProgressRing_Validation50_[#FF0000_#008000_#008000_#FF0000]_Progress-Ring-Value-50
    • DoesNotInterfereWithHorizontalDrag_UITests_Microsoft_UI_Xaml_Controls_RefreshContainerTests_RefreshContainerHorizontalScroll
    • FocusManager_GetFocusedElement_Button_Validation_FocusManager_-_GetFocusedElement_-_Button_-_2_-_After_Selection
    • FocusManager_GetFocusedElement_Button_Validation_FocusManager_-_GetFocusedElement_-_Button_-_1_-_Initial_State
    • FocusManager_FocusDirection_Down_Validation_Uno_UI_Samples_Content_UITests_FocusTests_FocusManager_FocusDirection
    • FocusManager_GetFocusedElement_Button_Validation_Uno_UI_Samples_Content_UITests_FocusTests_FocusManager_GetFocus_Automated
    • Detereminate_ProgressRing_Validation0_[#FF0000_#FF0000_#FF0000_#FF0000]_UITests_Microsoft_UI_Xaml_Controls_ProgressRing_WinUIDeterminateProgressRing
    • NativeCommandBar_Size_Uno_UI_Samples_Content_UITests_CommandBar_CommandBar_Dynamic
    • ProgressRing_IsEnabled_Running_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • ProgressRing_Visibility_Collapsed_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • When_Clipped_Rounded_Corners_UITests_Windows_UI_Xaml_Clipping_Clipping4273
    • When_Clip_Is_Set_On_Child_Element_original
    • When_MultipleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • UpDownEnabledTest_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
    • When_ExtendedSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_Clip_Is_Set_On_Child_Element_validation
    • When_Gyrometer_Is_Retrived_With_GetDefault_UITests_Shared_Windows_Devices_GyrometerTests
    • When_SingleSelectionWithItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_Click_Outside_Dialog_Expect_No_Dismiss_UITests_Shared_MessageDialogTests_MessageDialogTest
  • android-28-net8-Snap: 51 changed over 1067

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Gesture_Recognizer_Pointer_Events_test_bench_UITests_Shared_Windows_UI_Input_GestureRecognizer_PointersEvents
    • NavigationView_MUXControlsTestApp_NavigationViewCustomThemeResourcesPage_MUXControlsTestApp_NavigationViewCustomThemeResourcesPage
    • SwipeControl_MUXControlsTestApp_SwipeControlPage2_MUXControlsTestApp_SwipeControlPage2
    • NavigationView_MUXControlsTestApp_NavigationViewRS4Page_MUXControlsTestApp_NavigationViewRS4Page
    • ListView_ListViewSelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • MediaPlayerElement_Using_3gp_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_3gp_Extension
    • MediaPlayerElement_Using_mp3_Audio_only_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Mp3_Extension
    • MediaPlayerElement_Using_ogg_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Ogg_Extension
    • ListView_ListView_FirstLastCacheIndex_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListView_FirstLastCacheIndex
    • RatingControl_UITests_Microsoft_UI_Xaml_Controls_RatingControlTests_RatingControlPage_UITests_Microsoft_UI_Xaml_Controls_RatingControlTests_RatingControlPage
    • MediaPlayerElement_Mini_player_UITests_Shared_Windows_UI_Xaml_Controls_MediaPlayerElement_MediaPlayerElement_Minimal
    • Image_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_Icons_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_Icons
    • Image_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_NoSize_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_NoSize
    • MUX_NumberBox_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
    • WebView_UITests_Windows_UI_Xaml_Controls_WebView_WebView_Title_UITests_Windows_UI_Xaml_Controls_WebView_WebView_Title
    • UIElement_TransformToVisual_Simple_UITests_Shared_Windows_UI_Xaml_UIElementTests_TransformToVisual_Simple
    • UIElement_TransformToVisual_Transform_UITests_Shared_Windows_UI_Xaml_UIElementTests_TransformToVisual_Transform
    • UIElement_UITests_Shared_Windows_UI_Xaml_UIElementTests_UIElement_Layout_Constrains_UITests_Shared_Windows_UI_Xaml_UIElementTests_UIElement_Layout_Constrains
    • UIElement_UITests_Shared_Windows_UI_Xaml_UIElementTests_UIElement_Native_Child_UITests_Shared_Windows_UI_Xaml_UIElementTests_UIElement_Native_Child
    • TeachingTip_UITests_Microsoft_UI_Xaml_Controls_TeachingTipTests_TeachingTipPage_UITests_Microsoft_UI_Xaml_Controls_TeachingTipTests_TeachingTipPage
  • ios: 4 changed over 255

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • When_SingleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • ProgressRing_Visibility_Collapsed_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • TextBox_UpdatedBinding_On_OneWay_Mode_UITests_Windows_UI_Xaml_Controls_TextBox_TextBox_Bindings
    • ContentControl_Changing_ContentTemplate_Uno_UI_Samples_Content_UITests_ContentControlTestsControl_ContentControl_Changing_ContentTemplate
  • ios-Snap: 49 changed over 984

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Brushes_ImageBrushWithRotateTransform_Uno_UI_Samples_UITests_ImageBrushTestControl_ImageBrushWithRotateTransform
    • Default_Uno_UI_Samples_Content_UITests_WebView_WebView_AnchorNavigation_Uno_UI_Samples_Content_UITests_WebView_WebView_AnchorNavigation
    • Brushes_ImageBrushStretch2_Uno_UI_Samples_UITests_ImageBrushTestControl_ImageBrushStretch2
    • Brushes_UITests_Windows_UI_Xaml_Media_BrushesTests_RevealBrush_Fallback_UITests_Windows_UI_Xaml_Media_BrushesTests_RevealBrush_Fallback
    • Brushes_Uno_UI_Samples_Samples_Shared_Content_UITests_ImageBrushInList_Uno_UI_Samples_Samples_Shared_Content_UITests_ImageBrushInList
    • ColorPicker_WinUIColorPickerPage_UITests_Shared_Microsoft_UI_Xaml_Controls_ColorPickerTests_WinUIColorPickerPage
    • ColorPicker_ColorPickerSample_UITests_Microsoft_UI_Xaml_Controls_ColorPickerTests_ColorPickerSample
    • Image_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Vertical_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Vertical
    • Image_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Alignment_SizeOnControl_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Alignment_SizeOnControl
    • NavigationView_FluentStyle_NavigationViewSample_SamplesApp_Samples_Microsoft_UI_Xaml_Controls_NavigationViewTests_FluentStyle_FluentStyle_NavigationViewSample
    • TextBlock_TextBoxSizeChanging_Uno_UI_Samples_Content_UITests_TextBlockControl_TextBoxSizeChanging
    • NavigationView_MUXControlsTestApp_NavigationViewMenuItemStretchPage_MUXControlsTestApp_NavigationViewMenuItemStretchPage
    • NavigationView_MUXControlsTestApp_NavigationViewMinimalPage_MUXControlsTestApp_NavigationViewMinimalPage
    • TextBlock_TextBlockMultilineInStarStackPanel_Uno_UI_Samples_Content_UITests_TextBlockControl_TextBlockMultilineInStarStackPanel
    • WebView_UITests_Microsoft_UI_Xaml_Controls_WebView2Tests_WebView2_ExecuteScriptAsync_UITests_Microsoft_UI_Xaml_Controls_WebView2Tests_WebView2_ExecuteScriptAsync
    • WebView_UITests_Microsoft_UI_Xaml_Controls_WebView2Tests_WebView2_NavigationProperties_UITests_Microsoft_UI_Xaml_Controls_WebView2Tests_WebView2_NavigationProperties
    • Brushes_BorderImageBrush_Uno_UI_Samples_UITests_ImageBrushTestControl_BorderImageBrush
    • WebView_WebView2_Javascript_AlertConfirmPrompt_SamplesApp_Microsoft_UI_Xaml_Controls_WebView2Tests_WebView2ControlJavaScriptAlertConfirmPrompt
    • TextBlock_TextBlock_FixedWidth_With_DataBound_Run_Uno_UI_Samples_Content_UITests_TextBlockControl_TextBlock_FixedWidth_With_DataBound_Run
    • Brushes_PanelImageBrush_Uno_UI_Samples_UITests_ImageBrushTestControl_PanelImageBrush
  • skia-linux-screenshots: 61 changed over 2246

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Gamepad_Enumeration.png-dark
    • Gamepad_Enumeration.png
    • ButtonClippingTestsControl.png-dark
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
    • Image_Stretch_None.png-dark
    • Image_Stretch_None.png
    • ImageIconPage.png-dark
    • ImageIconPage.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • LargeImageList.png-dark
    • LargeImageList.png
  • skia-windows-screenshots: 61 changed over 2246

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • Focus_WASM_Tab.png-dark
    • Focus_WASM_Tab.png
    • DragDrop_ListView_Custom_States.png-dark
    • DragDrop_ListView_Custom_States.png
    • DragDrop_TestPage.png-dark
    • DragDrop_TestPage.png
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • FocusManager_FocusDirection.png-dark
    • FocusManager_FocusDirection.png
    • Buttons.png
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • LargeImageList.png-dark
    • LargeImageList.png
  • wasm: 54 changed over 1051

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • UITests.Shared.Windows_UI_Xaml_Controls.ComboBox.ComboBox_DropDownPlacement
    • UITests.Windows_UI_Xaml_Media_Animation.DoubleAnimation_FinalState_Opacity
    • UITests.Windows_UI_Xaml_Controls.ListView.ListViewItem_IsEnabled
    • UITests.Windows_UI_Xaml_Controls.ListView.ListView_DisplayMemberPath
    • UITests.Windows_UI_Xaml_Controls.ListView.ListView_DuplicateItem
    • UITests.Windows_UI_Xaml_Controls.SwipeControlTests.SwipeControl_ListView_ItemClick
    • Uno.UI.Samples.Content.UITests.CommandBar.CommandBar_Padding
    • UITests.Microsoft_UI_Xaml_Controls.InfoBadgeTests.InfoBadgePage
    • UITests.Shared.Windows_UI_Xaml_Controls.ContentDialogTests.ContentDialog_Closing
    • UITests.Shared.Windows_UI_Xaml_Controls.ContentDialogTests.ContentDialog_Simple
    • UITests.Windows_UI_Xaml.DragAndDrop.DragDrop_ListView_Custom_States
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewHeaderFooter_ImplicitlyBinded
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.UndefinedHeightListView
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • UITests.Shared.Windows_UI_Xaml_Controls.ComboBox.ComboBox_VisibleBounds
    • UITests.Shared.Windows_UI_Xaml_Controls.CommandBar.CommandBar_Xaml_Automated
    • UITests.Windows_UI_Xaml_Controls.BorderTests.BorderWithNullBrushAndNonZeroThickness
    • Uno.UI.Samples.Content.UITests.ButtonTestsControl.AppBar_KeyBoard
    • Uno.UI.Samples.Content.UITests.ButtonTestsControl.Buttons
  • wasm-automated-net9.0-WinUI-Benchmarks-automated: 0 changed over 1

  • wasm-automated-net9.0-WinUI-Default-automated: 14 changed over 876

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • When_MaxLines_Then_AlignmentPositionIsCorrect_Uno_UI_Samples_Content_UITests_TextBlockControl_SimpleText_MaxLines_Two_With_Wrap
    • Default_StrokeThickness_MyRect
    • ListView_SelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • Default_StrokeThickness_MyPolyline
    • Default_StrokeThickness_MyPath
    • Default_StrokeThickness_MyLine
    • SequentialAnimations_SamplesApp_Windows_UI_Xaml_Media_Animation_SequentialAnimationsPage
    • When_Padding_Is_Changed_Then_Cache_Is_Missed_UITests_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_MeasureCache
    • When_TextTrimming_Is_Set_Then_Ellipsis_Is_Used_UITests_Windows_UI_Xaml_Controls_TextBlockControl_TextBlock_TextTrimming
    • TestProgressRing_InitialState_UITests_Microsoft_UI_Xaml_Controls_ProgressRing_WinUIProgressRing_Features
    • When_SingleSelectionWithItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_NoSelection_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • Default_StrokeThickness_MyEllipse
    • Default_StrokeThickness_MyPolygon
  • wasm-automated-net9.0-WinUI-RuntimeTests-0: 0 changed over 1

  • wasm-automated-net9.0-WinUI-RuntimeTests-1: 1 changed over 1

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • RunRuntimeTests_SamplesApp_Samples_UnitTests_UnitTestsPage
  • wasm-automated-net9.0-WinUI-RuntimeTests-2: 1 changed over 1

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • RunRuntimeTests_SamplesApp_Samples_UnitTests_UnitTestsPage

@carldebilly
carldebilly merged commit 364fba6 into master May 22, 2025
@carldebilly
carldebilly deleted the dev/cdb/bugs/force-process-dpiawareness branch May 22, 2025 13:06
@mergify mergify Bot mentioned this pull request May 22, 2025
2 of 6 tasks
jeromelaban added a commit that referenced this pull request May 22, 2025
@HakanL

HakanL commented May 23, 2025

Copy link
Copy Markdown

Seems like it broke Linux #20544

DevTKSS pushed a commit to DevTKSS/uno that referenced this pull request May 31, 2025
…rce-process-dpiawareness

Add DPI awareness
jonpryor added a commit that referenced this pull request Nov 7, 2025
("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
jonpryor added a commit that referenced this pull request Nov 7, 2025
("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
jonpryor added a commit that referenced this pull request Nov 7, 2025
("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.
jonpryor added a commit that referenced this pull request Nov 7, 2025
("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-actions github-actions Bot locked as resolved and limited conversation to collaborators May 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

kind/bug Something isn't working kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.