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

Localization not work under iOS and Mac arm64 #16847

Closed
rolfbjarne opened this issue Nov 21, 2022 · 9 comments · Fixed by #17117
Closed

Localization not work under iOS and Mac arm64 #16847

rolfbjarne opened this issue Nov 21, 2022 · 9 comments · Fixed by #17117
Labels
bug If an issue is a bug or a pull request a bug fix
Milestone

Comments

@rolfbjarne
Copy link
Member

From @changguangyu on Fri, 18 Nov 2022 13:22:22 GMT

Description

Localization not work under iOS and Mac arm64.
It seems that <GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore> under these platform is broken.
The satellite assemblies are not included in output app package.

Right click 'Show package contents' on output Mac app, the satellite assemblies folder(e.g. zh-Hans) inside MonoBundle directory are empty. There should be ProjectName.resources.dll.

Steps to Reproduce

  1. Clone this project https://github.com/VladislavAntonyuk/MauiSamples/tree/main/MauiLocalization
  2. Compile with Visual Studio 17.4 with .Net 7.0

For Windows and Android, switch language is working fine, but on iOS and Mac arm64 it's not work.

The satellite assemblies are not included in output app package.

It seems that <GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore> is broken.

Link to public reproduction project repository

https://github.com/VladislavAntonyuk/MauiSamples/tree/main/MauiLocalization

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS, macOS

Affected platform versions

Mac x64 is working fine, arm not work

Did you find any workaround?

No response

Relevant log output

No response

Copied from original issue dotnet/maui#11474

@rolfbjarne
Copy link
Member Author

From @rachelkang on Fri, 18 Nov 2022 15:05:14 GMT

@rolfbjarne thoughts?

@rolfbjarne
Copy link
Member Author

From @rolfbjarne on Fri, 18 Nov 2022 16:11:40 GMT

@changguangyu

Right click 'Show package contents' on output Mac app, the satellite assemblies folder(e.g. zh-Hans) inside MonoBundle directory are empty. There should be ProjectName.resources.dll.

Your test project doesn't seem to contain any zh-Hans resources, but it contains a uk resource, which shows up in the uk subdirectory in the app bundle (for iOS apps) when I build on macOS using the command line:

MauiLocalization.app/uk/MauiLocalization.resources.dll

does it work for you if you build from the command line? If not, can you get a binary buildlog so that we can investigate where things go wrong for you?

@rolfbjarne
Copy link
Member Author

From @changguangyu on Sat, 19 Nov 2022 00:57:53 GMT

This is my build command: dotnet build -f:net7.0-maccatalyst -c:Release /bl:msbuild.binlog

The uk subdirectory at bin/Release/net7.0-maccatalyst/maccatalyst-x64/MauiLocalization.app/Contents/MonoBundle/uk is fine. But bin/Release/net7.0-maccatalyst/MauiLocalization.app/Contents/MonoBundle/uk is empty.

Here is my build log.
msbuild.binlog.zip

@rolfbjarne
Copy link
Member Author

From @changguangyu on Mon, 21 Nov 2022 01:01:56 GMT

The issue also exists in iOS App Store distribution package(but does not appear when test the app in both debug and release mode, physical device and stimulator). I think MAUI is not a proper choice for production at this time. Not because bugs of MAUI, but the difference between the final distribution package and release mode package, which makes MAUI totally not reliable.

@rolfbjarne
Copy link
Member Author

From @changguangyu on Mon, 21 Nov 2022 03:09:28 GMT

Edit: Tested again. On iOS App Store distribution package it is another issue. uk folder is not empty, but switch language not work.

@rolfbjarne
Copy link
Member Author

From @changguangyu on Mon, 21 Nov 2022 05:18:45 GMT

Still cannot solve this issue.

@rolfbjarne
Copy link
Member Author

From @changguangyu on Mon, 21 Nov 2022 05:41:10 GMT

Temporary Fix for Mac: Add <RuntimeIdentifiers>maccatalyst-x64</RuntimeIdentifiers> to force build a x64 only Mac package( Prevent build universal package for x64 and arm64).

@rolfbjarne
Copy link
Member Author

I can reproduce the problems when building a universal Mac Catalyst app (which is now the default for Release builds).

There are at least two factors contributing to the problem:

  1. The default for EnableAssemblyILStripping is different between maccatalyst-x64 and maccatalyst-arm64, which leads to only one of the MauiLocalization.resources.dll assemblies to be stripped, which makes them different, and as such they can't both be put in the expected location.
  2. The MauiLocalization.dll assemblies are also different (even when EnableAssemblyILStripping is set to false for both RIDs), which causes the dependent MauiLocalization.resources.dll to be treated as different as well. This is because of the /debug:portable flag passed to csc (probably due to paths embedded in the debug info)
  3. The MauiLocalization.dll is still different when disabling debug info (<DebugType>none</DebugType>, because the /platform:... flag to csc is different. This can be fixed by setting <PlatformType>AnyCPU</PlatformType>.
  4. The MauiLocalization.dll is still different even after using AnyCPU as the platform type. I haven't been able to figure out why yet, because if I copy the csc command from the binlog I get a different binary (and they're identical between x64 and arm64), so maybe there's an environment variable during the build that changes how csc creates assemblies.

Things we'll probably need to do:

  1. Make EnableAssemblyILStripping default to the same value for universal builds.
  2. Figure out a way to make resource assemblies load properly when they're different for each platform for universal builds.

@rolfbjarne rolfbjarne added this to the .NET 8 milestone Nov 21, 2022
@rolfbjarne rolfbjarne added the bug If an issue is a bug or a pull request a bug fix label Nov 21, 2022
@rolfbjarne rolfbjarne added this to Bugs in .NET 8 - Themes Nov 21, 2022
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Dec 22, 2022
…amarin#16847.

If we're creating a universal app, and here are satellite assemblies that are not
identical across all RuntimeIdentifiers, those assemblies will be stored in a RuntimeIdentifier-specific
subdirectory during the build.

Unfortunately we didn't know how to find those assemblies at runtime, causing localizations
in universal apps to not work.

This change will:

* Add support for looking in the directory where RID-specific satellite assemblies
  are stored.
* Add an assembly resolution event handler to our CoreCLR bridge so that we can
  execute our custom lookup code.
* Add a assembly resource lookup test to monotouch-test.
* Add a macOS + Mac Catalyst variation of monotouch-test to xharness that triggers
  the bug (a universal test app).

Fixes xamarin#16847.
@rolfbjarne
Copy link
Member Author

  1. Make EnableAssemblyILStripping default to the same value for universal builds.

I've moved this to its own issue: #17115.

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Dec 23, 2022
…amarin#16847.

If we're creating a universal app, and here are satellite assemblies that are not
identical across all RuntimeIdentifiers, those assemblies will be stored in a RuntimeIdentifier-specific
subdirectory during the build.

Unfortunately we didn't know how to find those assemblies at runtime, causing localizations
in universal apps to not work.

This change will:

* Add support for looking in the directory where RID-specific satellite assemblies
  are stored.
* Add an assembly resolution event handler to our CoreCLR bridge so that we can
  execute our custom lookup code.
* Add a assembly resource lookup test to monotouch-test.
* Add a macOS + Mac Catalyst variation of monotouch-test to xharness that triggers
  the bug (a universal test app).

Fixes xamarin#16847.
rolfbjarne added a commit that referenced this issue Jan 13, 2023
…16847. (#17117)

If we're creating a universal app, and here are satellite assemblies that are not
identical across all RuntimeIdentifiers, those assemblies will be stored in a RuntimeIdentifier-specific
subdirectory during the build.

Unfortunately we didn't know how to find those assemblies at runtime, causing localizations
in universal apps to not work.

This change will:

* Add support for looking in the directory where RID-specific satellite assemblies
  are stored.
* Add an assembly resolution event handler to our CoreCLR bridge so that we can
  execute our custom lookup code.
* Add an assembly resource lookup test to monotouch-test.
* Add a macOS + Mac Catalyst variation of monotouch-test to xharness that triggers
  the bug (a universal test app).

Fixes #16847.
.NET 8 - Themes automation moved this from Bugs to Done Jan 13, 2023
dustin-wojciechowski pushed a commit to dustin-wojciechowski/xamarin-macios that referenced this issue Jan 19, 2023
…amarin#16847. (xamarin#17117)

If we're creating a universal app, and here are satellite assemblies that are not
identical across all RuntimeIdentifiers, those assemblies will be stored in a RuntimeIdentifier-specific
subdirectory during the build.

Unfortunately we didn't know how to find those assemblies at runtime, causing localizations
in universal apps to not work.

This change will:

* Add support for looking in the directory where RID-specific satellite assemblies
  are stored.
* Add an assembly resolution event handler to our CoreCLR bridge so that we can
  execute our custom lookup code.
* Add an assembly resource lookup test to monotouch-test.
* Add a macOS + Mac Catalyst variation of monotouch-test to xharness that triggers
  the bug (a universal test app).

Fixes xamarin#16847.
@ghost ghost locked as resolved and limited conversation to collaborators Feb 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug If an issue is a bug or a pull request a bug fix
Projects
No open projects
1 participant