[Trimming] Fix remaining trimming warnings related to XAML parsing#20474
Conversation
|
/rebase |
…able-property-converter-warnings
| { | ||
| if (!RuntimeFeature.IsXamlRuntimeParsingSupported) | ||
| { | ||
| throw new NotSupportedException("XAML runtime parsing is not supported. " + |
There was a problem hiding this comment.
Should this be a localized message ?
There was a problem hiding this comment.
I don't think this should be localized but I'm not sure what our guidelines for localization are. This exception shouldn't be reached under normal circumstances and it's mostly there to guide the trimmer. Also, maybe the NotSupportedException isn't the right exception here and I should change it to InvalidOperationException (to keep it in line with https://github.com/dotnet/maui/blob/net9.0/src/Controls/src/Core/ResourceDictionary.cs#L65 ?)
There was a problem hiding this comment.
we don't localize runtime exception. only compile time ones
There was a problem hiding this comment.
indeed, InvalidOperationException is probably better
| object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider) | ||
| { | ||
| if (!RuntimeFeature.IsXamlRuntimeParsingSupported) | ||
| { | ||
| throw new InvalidOperationException(RuntimeFeature.XamlRuntimeParsingNotSupportedErrorMessage); | ||
| } |
There was a problem hiding this comment.
It looks like the converter has a XamlC (build-time) replacement:
maui/src/Controls/src/Core/BindablePropertyConverter.cs
Lines 15 to 16 in d87c181
So it seems we should be fine to throw here.
There was a problem hiding this comment.
Yes, XamlC uses the other class to generate the IL directly. The code that I added to throw won't be ever called for any XAML that's compiled. It can only be reached if the developer manually calls LoadFromXaml.
|
Test failures seem unrelated to this PR to me. |
Description of Change
This PR fixes 5 trimming warnings in 2 scenarios which are related to runtime XAML parsing:
BindablePropertyConverter- the converter is completely unused when all XAML is compiled because there is a compiled version of the converter (Microsoft.Maui.Controls.XamlC.BindablePropertyConverter). This code is analyzed by ILC because it is linked through the[TypeConverter]attribute onBindableProperty. The exceptions will be thrown in the scenario when XAML runtime parsing is disabled and the developer callsLoadFromXaml().XamlParser- theXamlParser.GetElementTypeis called (only) fromXamlServiceProviderthroughIXamlTypeResolver. TheIXamlTypeResolveris only used when parsing XAML at runtime. Code generated by the XAML compiler which usesXamlServiceProviderdoesn't need to useIXamlTypeResovler.Issues Fixed
Contributes to #19397
/cc @StephaneDelcroix