Skip to content

NativeAOT -> WinForms reflection exception (System.Globalization.CultureNotFoundException) #90

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

Open
mark1145 opened this issue Jan 27, 2025 · 0 comments

Comments

@mark1145
Copy link

mark1145 commented Jan 27, 2025

Hi team,

Thank you so much for making this library and all the hard work to get WinForms working with NativeAOT. I'm using it for the game client on my free server.

Essentially my C# game client has a WinForms "assistant" that helps reduce repetitive clicks in the game. Everything (mostly) works with NativeAOT, but very rarely the below exception occurs. It seems to affect none-english systems moreso. Kindly find the calling code here:
https://github.com/markdwags/Razor/blob/master/Razor/Core/Main.cs#L356

I've tried the following to resolve it:

  1. in rd.xml add:
    <Assembly Name="System.Globalization"> <Type Name="System.Globalization.CultureInfo" Dynamic="Required All" /> </Assembly>
  2. in .csjproj add:
    <InvariantGlobalization>true</InvariantGlobalization>

The actual exception seems to be coming from:
https://github.com/dotnet/winforms/blob/main/src/System.Windows.Forms/src/System/Windows/Forms/NativeWindow.cs#L340

Exception:
System.Globalization.CultureNotFoundException: Argument_CultureNotSupportedInInvariantMode Arg_ParamName_Name, name
Argument_CultureInvalidIdentifier, zh-Hant
at System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride) + 0x8e
at System.Reflection.AssemblyName.set_CultureName(String) + 0x32
at System.Reflection.RuntimeAssemblyName.CopyToAssemblyName(AssemblyName) + 0x3c
at System.Reflection.Runtime.Assemblies.RuntimeAssemblyInfo.GetName() + 0x35
at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception) + 0x9c3
at System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception) + 0xd6
at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam) + 0xe1
at ClassicUO!+0x18d94aa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant