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 Android ShellSearchViewAdapter when SearchHandler.DisplayMemberName is set but the MSBuild property MauiShellSearchResultsRendererDisplayMemberNameSupported is not enabled. DisplayMemberName uses reflection-based binding which is not trimming-safe, so it is disabled by default. The error explains how to enable it via the build property but warns it may break under NativeAOT or full trimming.
Source
Thrown at src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSearchViewAdapter.cs:89
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<ShellSearchViewAdapter>()?.LogError(TrimmerConstants.SearchHandlerDisplayMemberNameNotSupportedWarning);
throw new InvalidOperationException(TrimmerConstants.SearchHandlerDisplayMemberNameNotSupportedWarning);
}
#pragma warning restore CS0618
}
label.HorizontalTextAlignment = TextAlignment.Center;
label.VerticalTextAlignment = TextAlignment.Center;
return label;
});
}
return _defaultTemplate;
}
}
ISearchHandlerController SearchController => _searchHandler;
public override Java.Lang.Object GetItem(int position)
{View on GitHub (pinned to f377ff1c5e)
Solutions
- Implement a custom ItemTemplate for the SearchHandler instead of using DisplayMemberName — bind the Label.Text to the desired property explicitly in XAML or code.
- If reflection-based DisplayMemberName is required and the app is not trimmed/NativeAOT, add `<MauiShellSearchResultsRendererDisplayMemberNameSupported>true</MauiShellSearchResultsRendererDisplayMemberNameSupported>` to the .csproj.
- Remove the DisplayMemberName assignment and use DataTemplate with explicit bindings for trim safety.
Example fix
// before
SearchHandler.DisplayMemberName = "ProductName";
// after (recommended: custom ItemTemplate)
SearchHandler.ResultsTemplate = new DataTemplate(() =>
{
var label = new Label();
label.SetBinding(Label.TextProperty, "ProductName");
return label;
});
// OR enable the build property (not trim-safe):
// In .csproj: <MauiShellSearchResultsRendererDisplayMemberNameSupported>true</MauiShellSearchResultsRendererDisplayMemberNameSupported> Defensive patterns
Strategy: validation
Validate before calling
// Check before setting DisplayMemberName var isSupported = AppInfo.Current?.PackageName != null; // runtime proxy // Simpler: use a custom ItemTemplate instead
Type guard
public static bool IsDisplayMemberNameSupported()
#if MAUI_SHELL_SEARCHRESULTS_RENDERER_DISPLAYMEMBERNAME_SUPPORTED
=> true;
#else
=> false;
#endif Prevention
- Use custom ItemTemplate instead of DisplayMemberName for trim-safe code.
- Enable the MSBuild property only if not targeting NativeAOT/trimmed builds.
- Add a build-time check or analyser to flag DisplayMemberName usage.
When it happens
Trigger: At line 89: when `_searchHandler.DisplayMemberName is not null` and the trimmer-safe path is active (DisplayMemberName support not enabled). The code first logs an error, then throws InvalidOperationException. This fires whenever a SearchHandler is configured with DisplayMemberName set to a property name string without enabling the corresponding MSBuild flag.
Common situations: 1) Setting `SearchHandler.DisplayMemberName = "Name"` on a Shell SearchHandler without enabling the build property. 2) Migrating from Xamarin.Forms where DisplayMemberName worked without additional configuration. 3) Published/Release builds where trimming is aggressive and the reflection-based binding would fail at runtime. 4) Apps targeting NativeAOT where reflection-based member access is not supported.
Related errors
- DisplayMemberName is not supported. Consider implementing cu
- LoadView must be called before accessing View
- Active Shell Item not set. Have you added any Shell Items to
- Content not found for active {ShellItem}. Title: {ShellItem.
- Unexpected navigation type
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/e4a721b5b6569c80.
Report an issue: GitHub.