Skip to content

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

@mark1145

Description

@mark1145

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions