You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Encoding.ASCII is trimmed in Android/iOS in .NET8 #97576
When trimming is enabled I cannot retrieve ASCII Encoding object. It looks like it's removed from Environment variables. It's working when trimmiing is disabled. Sample attached:
Expected:
Click button
Button text will update with Encoding name (US-ASCII) and encoding object will be initiated
Actual:
Click button
Button text updates with incorrect name: Globalization_cp_20127 and then crashes when trying to retrieve encoding object
I tried to include in Linker.xml:
but unfortunately it didn't help.
Steps to Reproduce
Create project in Maui (can be Android or iOS)
Enable trimming
Try to invoke: System.Text.Encoding.GetEncoding(System.Text.Encoding.ASCII.EncodingName, EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback.
Encoding ASCII: Globalization_cp_20127
Argument_EncodingNotSupported, Globalization_cp_20127 Arg_ParamName_Name, name
System.ArgumentException: Argument_EncodingNotSupported, Globalization_cp_20127 Arg_ParamName_Name, name
at System.Text.EncodingTable.InternalGetCodePageFromName(String )
at System.Text.EncodingTable.GetCodePageFromName(String )
at System.Text.Encoding.GetEncoding(String , EncoderFallback , DecoderFallback )
This is because of resource stripping.
To reduce application size, we strip all string resources from CoreLib - this will remove the resources used by EncodingTable.GetDisplayNamelink.
This means that in trimmed app the display name is returned as the "wrong" Globalization_cp_20127 since that's the resource key name. But the reverse lookup table which is in
This is basically a problem where the display name is broken when UseSystemResourceKeys=true which is the default for all mobile and Blazor projects. @jeffhandley I'll leave it up to you to decide what to do about this - I'll be glad to help with the technical specifics around trimming if needed.
Activity
jeffschwMSFT commentedon Jan 29, 2024
fyi, we are deprecating area-corelib-mono and replacing with specific areas paths
vitek-karas commentedon Mar 1, 2024
This is because of resource stripping.
To reduce application size, we strip all string resources from CoreLib - this will remove the resources used by
EncodingTable.GetDisplayNamelink.This means that in trimmed app the display name is returned as the "wrong"
Globalization_cp_20127since that's the resource key name. But the reverse lookup table which is inruntime/src/libraries/System.Private.CoreLib/src/System/Text/EncodingData.cs
Line 19 in a2e4177
The correct usage is to use
WebNameinstead - see the docs here https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.getencoding?view=net-8.0#system-text-encoding-getencoding(system-string). It states that anyWebNameis valid.EncodingNameis a humanly readable string, potentially localized, so the reverse lookup won't work for it.That said - it's a good question if MAUI should be trimming encoding display names in the first place.
@jeffhandley as the owner of the System.Text.Encoding - mostly for opinions on the behavior of trimmed app as described above.
vitek-karas commentedon Jul 9, 2024
This is basically a problem where the display name is broken when
UseSystemResourceKeys=truewhich is the default for all mobile and Blazor projects. @jeffhandley I'll leave it up to you to decide what to do about this - I'll be glad to help with the technical specifics around trimming if needed.