dotnet/maui · error · InvalidOperationException

DisplayMemberName is not supported. Consider implementing cu

Error message

DisplayMemberName is not supported. Consider implementing custom ItemTemplate instead. Alternatively, enable DisplayMemberName by setting the $(MauiShellSearchResultsRendererDisplayMemberNameSupported) MSBuild property to true. Note: DisplayMemberName is not trimming-safe and it might not work as expected in NativeAOT or fully trimmed apps.

What it means

Thrown by the iOS ShellSearchResultsRenderer when SearchHandler.DisplayMemberName is set but the MSBuild property MauiShellSearchResultsRendererDisplayMemberNameSupported is not enabled. This is the iOS counterpart to error 447. DisplayMemberName relies on reflection-based binding which is incompatible with trimming and NativeAOT, so it is disabled by default and throws when used without the opt-in build flag.

Source

Thrown at src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSearchResultsRenderer.cs:60

						if (RuntimeFeature.IsShellSearchResultsRendererDisplayMemberNameSupported)
						{
#pragma warning disable CS0618
#if NET8_0
#pragma warning disable IL2026 // FeatureGuardAttribute is not supported on .NET 8
#endif
							label.SetBinding(Label.TextProperty, SearchHandler.DisplayMemberName ?? ".");
#if NET8_0
#pragma warning restore IL2026 // FeatureGuardAttribute is not supported on .NET 8
#endif
#pragma warning restore CS0618
						}
						else
						{
#pragma warning disable CS0618
							if (SearchHandler.DisplayMemberName is not null)
							{
								Application.Current?.FindMauiContext()?.CreateLogger<ShellSearchResultsRenderer>()?.LogError(TrimmerConstants.SearchHandlerDisplayMemberNameNotSupportedWarning);
								throw new InvalidOperationException(TrimmerConstants.SearchHandlerDisplayMemberNameNotSupportedWarning);
							}
#pragma warning restore CS0618

							label.SetBinding(Label.TextProperty, static (object o) => o);
						}

						label.HorizontalTextAlignment = TextAlignment.Center;
						label.VerticalTextAlignment = TextAlignment.Center;

						return label;
					}));
			}
		}

		public event EventHandler<object> ItemSelected;

		public ShellSearchResultsRenderer(IShellContext context)
		{

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Replace DisplayMemberName with a custom ItemTemplate that explicitly binds the display property.
  2. Enable the build property if trim-safety is not a concern: add `<MauiShellSearchResultsRendererDisplayMemberNameSupported>true</MauiShellSearchResultsRendererDisplayMemberNameSupported>` to .csproj.
  3. Remove the DisplayMemberName assignment entirely and use explicit DataTemplate bindings.

Example fix

// before
SearchHandler.DisplayMemberName = "Title";

// after — custom ItemTemplate (trim-safe)
SearchHandler.ResultsTemplate = new DataTemplate(() =>
{
    var label = new Label();
    label.SetBinding(Label.TextProperty, "Title");
    return label;
});

// OR enable in .csproj (not trim-safe):
// <MauiShellSearchResultsRendererDisplayMemberNameSupported>true</MauiShellSearchResultsRendererDisplayMemberNameSupported>
Defensive patterns

Strategy: validation

Validate before calling

// Use ItemTemplate instead of DisplayMemberName
// Before setting DisplayMemberName, check build support at compile time
#if !MAUI_SHELL_SEARCHRESULTS_RENDERER_DISPLAYMEMBERNAME_SUPPORTED
// Do not set DisplayMemberName — use ItemTemplate
#endif

Type guard

public static bool IsDisplayMemberNameSupported()
#if MAUI_SHELL_SEARCHRESULTS_RENDERER_DISPLAYMEMBERNAME_SUPPORTED
    => true;
#else
    => false;
#endif

Prevention

When it happens

Trigger: At line 60: when `SearchHandler.DisplayMemberName is not null` and the trimming-safe path is active. The renderer first logs an error then throws InvalidOperationException. Fires when a SearchHandler on iOS uses DisplayMemberName without enabling the corresponding MSBuild property.

Common situations: 1) Setting SearchHandler.DisplayMemberName in XAML or code on iOS without the build property. 2) Migrating from Xamarin.Forms Shell where DisplayMemberName worked by default. 3) Release builds with trimming where reflection-based binding would fail. 4) NativeAOT scenarios.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/d9327ad975733d15. Report an issue: GitHub.