-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Trimming] Fix remaining trimming warnings related to XAML parsing #20474
[Trimming] Fix remaining trimming warnings related to XAML parsing #20474
Conversation
/rebase |
…able-property-converter-warnings
@@ -23,6 +24,13 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati | |||
|
|||
object IExtendedTypeConverter.ConvertFromInvariantString(string value, IServiceProvider serviceProvider) | |||
{ | |||
if (!RuntimeFeature.IsXamlRuntimeParsingSupported) | |||
{ | |||
throw new NotSupportedException("XAML runtime parsing is not supported. " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a localized message ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't localize runtime exception. only compile time ones
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the converter has a XamlC (build-time) replacement:
maui/src/Controls/src/Core/BindablePropertyConverter.cs
Lines 15 to 16 in d87c181
[Xaml.ProvideCompiled("Microsoft.Maui.Controls.XamlC.BindablePropertyConverter")] | |
public sealed class BindablePropertyConverter : TypeConverter, IExtendedTypeConverter |
So it seems we should be fine to throw here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.GetElementType
is called (only) fromXamlServiceProvider
throughIXamlTypeResolver
. TheIXamlTypeResolver
is only used when parsing XAML at runtime. Code generated by the XAML compiler which usesXamlServiceProvider
doesn't need to useIXamlTypeResovler
.Issues Fixed
Contributes to #19397
/cc @StephaneDelcroix