dotnet / docs-maui

This repository contains documentation for .NET Multi-platform App UI (MAUI).
https://docs.microsoft.com/dotnet/maui
Creative Commons Attribution 4.0 International
222 stars 194 forks source link

.NET MAUI 9: Markup extensions and extended type converters need `[RequiresService(typeof(T))]` or `[AcceptEmptyServiceProvider]` annotations #2486

Open simonrozsival opened 1 week ago

simonrozsival commented 1 week ago

Help make content visible

In .NET MAUI 9, we now require all classes implementing IMarkupExtension, IMarkupExtension<T>, IValueProvider, and IExtendedTypeConverter to be annotated with either [RequireService(typeof(T))] or [AcceptEmptyServiceProvider] attributes. This was introduced in https://github.com/dotnet/maui/pull/19945.

In a migration guide or release notes, we should tell customers how to address warnings they might see, such as in the case of https://github.com/dotnet/maui/issues/24736:

XamlC warning XC0103: Consider attributing the markup extension "CommunityToolkit.Maui.Converters.IsNullConverter" with [RequireService] or [AcceptEmptyServiceProvider] if it doesn't require any.

Describe the change

We introduced a new optimization to XamlC which allows us to generate more efficient code when compiling XAML. This optimization helps reduce the final app size and also improve runtime performance.

Create XAML markup extensions

The example should be updated:

+[AcceptEmptyServiceProvider]
 public class HslColorExtension : IMarkupExtension<Color>
 {

The "Service providers" section

We should add a new paragraph describing the change:

/cc @StephaneDelcroix @davidbritch


Associated WorkItem - 314394

davidbritch commented 5 days ago

In a migration guide or release notes, we should tell customers how to address warnings they might see, such as in the case of https://github.com/dotnet/maui/issues/24736:

@simonrozsival That should be handled in the breaking changes docs, which are an engineering responsibility to provide.