Skip to content

[.NET 11] Migrate off internal MAUI APIs before InternalsVisibleTo removal #3097

@jfversluis

Description

@jfversluis

Summary

In .NET 11, InternalsVisibleTo for the .NET MAUI Community Toolkit will be removed from all MAUI assemblies (see dotnet/maui#34070).

This was attempted twice before for .NET 10 (dotnet/maui#28994, dotnet/maui#33442) but had to be reverted both times because the toolkit hadn't migrated off internal APIs yet.

This issue tracks the toolkit-side work needed to complete the migration.

Internal APIs That Can Be Fixed Now (Public Alternatives Exist)

These can be addressed on the toolkit side without any MAUI changes:

API Toolkit Usage Migration Path
InvalidateMeasureInternal(InvalidationTrigger) AvatarView.shared.cs (2 call sites) Replace with public InvalidateMeasure()
XamlParseException(string, IServiceProvider) AppThemeResourceExtension.shared.cs (5 call sites) Switch to public ctor XamlParseException(string, IXmlLineInfo)
GetDefaultFontSize() AvatarView.shared.cs (1 call site) Resolve IFontManager.DefaultFontSize from Handler.MauiContext.Services
RequireFontManager() Snackbar.android.cs, UIFontExtensions.macios.cs Resolve IFontManager from MauiContext.Services.GetRequiredService<IFontManager>()
AppThemeBinding AppThemeObject.shared.cs (1 call site) Already public on net11.0 — no change needed
GetTargetOrDefault() Snackbar.shared.cs Already self-solved — toolkit has own copy in WeakReferenceExtensions.cs

Internal APIs That Require MAUI to Provide Public Alternatives

These are blocked until MAUI makes them public (tracked in dotnet/maui#34070):

API Toolkit Usage Affected Controls
FontElement (static class) FontAttributesProperty, FontAutoScalingEnabledProperty, FontFamilyProperty, FontSizeProperty AvatarView
TextElement (static class) TextColorProperty, TextTransformProperty, CharacterSpacingProperty AvatarView
ImageElement (static class) SourceProperty, AspectProperty AvatarView, TouchBehavior, ImageTouchBehavior
IResourcesProvider (interface) Pattern match on IsResourcesCreated AppThemeResourceExtension
ImageSource.CancellationTokenSource private protected property access GravatarImageSource
StreamWrapper StreamWrapper.GetStreamAsync() HttpClientExtensions (used by GravatarImageSource)

Affected Toolkit Controls/Features

Control Internal APIs Used Can Fix Now?
AvatarView FontElement, TextElement, ImageElement, GetDefaultFontSize(), InvalidateMeasureInternal() Partially
AppThemeObject AppThemeBinding ✅ Yes (public in .NET 11)
AppThemeResourceExtension IResourcesProvider, XamlParseException internal ctor Partially
GravatarImageSource ImageSource.CancellationTokenSource, StreamWrapper ❌ Blocked on MAUI
Snackbar RequireFontManager() ✅ Yes
TouchBehavior / ImageTouchBehavior ImageElement ❌ Blocked on MAUI
UIFont extensions RequireFontManager() ✅ Yes

Suggested Approach

  1. Immediately: Migrate the 6 APIs that have public alternatives (listed above)
  2. When MAUI provides public types: Migrate FontElement, TextElement, ImageElement, IResourcesProvider, ImageSource.CancellationTokenSource, StreamWrapper
  3. For StreamWrapper: Consider rewriting HttpClientExtensions to use HttpClient directly instead of depending on MAUI's internal wrapper

Related Issues & PRs

cc @TheCodeTraveler @jfversluis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions