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

Fix locale (icudt.dat) related stuff when targeting iOS #53

Closed
lemonmojo opened this issue Jul 13, 2023 · 7 comments
Closed

Fix locale (icudt.dat) related stuff when targeting iOS #53

lemonmojo opened this issue Jul 13, 2023 · 7 comments

Comments

@lemonmojo
Copy link
Member

lemonmojo commented Jul 13, 2023

Some unit tests succeed when targeting macOS but fail when targeting the iOS simulator.
They are marked with // TODO: Test fails on iOS.

@lemonmojo
Copy link
Member Author

Just verified on an actual iPhone; fails as well.

@lemonmojo
Copy link
Member Author

Here's a list of all the APIs I've found to SIGSEGV up until now:

System.Type.GetType
System.String.IndexOf
System.DateTime.Now
System.Globalization.CultureInfo ctor
System.Version ctor
System.Version.TryParse
System.Convert.ToInt32
System.Reflection.Assembly.GetName
System.Decimal.TryParse

@lemonmojo
Copy link
Member Author

Setting InvariantGlobalization in the csproj to true works around the crashes but makes tests using a specific culture fail.

@lemonmojo
Copy link
Member Author

Can also be fixed by having <RuntimeHostConfigurationOption Include="ICU_DAT_FILE_PATH" Value="icudt.dat" /> in the csproj and including a copy of icudt.dat in the bundle.
The file can be found in the NuGet cache (ie. ~/.nuget/packages/microsoft.netcore.app.runtime.nativeaot.ios-arm64/8.0.0-preview.6.23329.7/runtimes/ios-arm64/native/icudt.dat)

@lemonmojo lemonmojo changed the title Find out why some tests fail when targeting the iOS Simulator Fix locale (icudt.dat) related stuff when targeting iOS Jul 13, 2023
@lemonmojo
Copy link
Member Author

lemonmojo commented Jul 13, 2023

Unfortunately that doesn't work in a XCTest bundle because the runtime locates the file by using -[NSBundle mainBundle].
See dotnet/runtime#88835 and xamarin/xamarin-macios#18471 (comment)

@lemonmojo
Copy link
Member Author

Might be able to work around this by calling AppContext.SetData("ICU_DAT_FILE_PATH", "<path>") early on in startup.

@lemonmojo
Copy link
Member Author

Using System.AppContext to set the icudt.dat file path at runtime does indeed work.
See f2d4f2b.

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