Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crashing in non-Windows environments #9

Closed
2 of 3 tasks
Aldaviva opened this issue Jul 31, 2023 · 2 comments
Closed
2 of 3 tasks

Avoid crashing in non-Windows environments #9

Aldaviva opened this issue Jul 31, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@Aldaviva
Copy link
Owner

Aldaviva commented Jul 31, 2023

See report of crashes with Wine. It is not clear what the root cause is, as there is no stack trace to show which method call fails, the error message, or what exception class it throws. Typically, catching Win32Exception is good enough, but it may also be a native fault in unmanaged code.

It may also be smart to double-check that it doesn't crash in older Windows versions that, like Wine, don't contain the required DWM methods. I already tested this in Windows 7 before, but there may be a problem there now given the Wine crashes.

KeePass has good instructions of how to run .NET programs with Mono and Wine.

  • Wine
  • Mono
  • Windows 7
@Aldaviva Aldaviva added the enhancement New feature or request label Jul 31, 2023
@Aldaviva Aldaviva added this to the 2.3.0 milestone Jul 31, 2023
@Aldaviva Aldaviva self-assigned this Jul 31, 2023
@Aldaviva
Copy link
Owner Author

Aldaviva commented Aug 1, 2023

Wine

Fedora 38 x64
Wine 8.12 from Fedora package repository

Setup

DO NOT install "Wine Windows Program Launcher" from the Fedora Software GUI, because that will crash with the error 0110:err:module:load_wow64_ntdll failed to load L"\\??\\C:\\windows\\syswow64\\ntdll.dll" error c0000135.

sudo dnf install wine winetricks
env WINEPREFIX=$HOME/winedotnet wineboot --init
env WINEPREFIX=$HOME/winedotnet wine uninstaller --remove '{E45D8920-A758-4088-B6C6-31DBB276992E}' # Keep Mono and Wine separate
env WINEPREFIX=$HOME/winedotnet winetricks --force dotnet48 corefonts

Testing

env WINEPREFIX=$HOME/winedotnet wine ./darknet-demo-winforms.exe
Unhandled Exception: System.EntryPointNotFoundException: Unable to find an entry point named '#133' in DLL 'uxtheme.dll'.
   at Dark.Net.Win32.AllowDarkModeForWindow(IntPtr window, Boolean isDarkModeAllowed)
   at Dark.Net.DarkNet.SetModeForWindow(IntPtr windowHandle, Theme windowTheme, ThemeOptions options) in C:\Users\Ben\Documents\Projects\darknet\darknet\DarkNet.cs:line 195
   at Dark.Net.DarkNet.SetWindowThemeForms(Form window, Theme theme, ThemeOptions options) in C:\Users\Ben\Documents\Projects\darknet\darknet\DarkNet.cs:line 147
   at darknet_demo_winforms.Program.Main() in C:\Users\Ben\Documents\Projects\darknet\darknet-demo-winforms\Program.cs:line 23

So it looks like we just need to handle the managed exception EntryPointNotFoundException.

Mono

Fedora 38 x64
Mono 6.12.0 from Fedora package repository

Setup

sudo dnf install mono-complete # includes mono-winforms

Testing

mono ./darknet-demo-winforms.exe
Could not load signature of Dark.Net.DarkNet:SetWindowThemeWpf due to: Could not load file or assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
Could not load signature of Dark.Net.IDarkNet:SetWindowThemeWpf due to: Could not load file or assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

Unhandled Exception:
System.TypeLoadException: Could not resolve the signature of a virtual method
  at darknet_demo_winforms.Program.Main () [0x0000e] in <600f536d9aef4f6994f5b7c786f46b5a>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not resolve the signature of a virtual method
  at darknet_demo_winforms.Program.Main () [0x0000e] in <600f536d9aef4f6994f5b7c786f46b5a>:0

The older DarkNet-Forms 1 avoided this by not having any methods that referred to any WPF types at all, using conditional compilation. With DarkNet 2, consumer Forms projects still don't have to refer to PresentationFramework, but some of the methods (even when not called) still refer to WPF types.

I don't think this can be fixed in one assembly without using reflection instead of strong typing.

Windows 7

Continues to work fine, does not throw EntryPointNotFoundException, even though the entry points in question did not exist in uxtheme.dll. Those P/Invoke calls are just no-ops.

Aldaviva added a commit that referenced this issue Aug 1, 2023
@Aldaviva
Copy link
Owner Author

Aldaviva commented Aug 1, 2023

The Forms demo runs fine in Wine if we just catch EntryPointNotFoundException or Exception every place we call the secret UXTheme methods.

@Aldaviva Aldaviva closed this as completed Aug 1, 2023
@Aldaviva Aldaviva changed the title Avoid crashing in Mono or Wine environments Avoid crashing in non-Windows environments Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant