{"record":{"id":"e4a721b5b6569c80","repo":"dotnet/maui","slug":"displaymembername-is-not-supported-consider-imple","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSearchViewAdapter.cs","lineNumber":89,"sourceCode":"\t\t\t\t\t\tif (RuntimeFeature.IsShellSearchResultsRendererDisplayMemberNameSupported)\n\t\t\t\t\t\t{\n#pragma warning disable CS0618\n#if NET8_0\n#pragma warning disable IL2026 // FeatureGuardAttribute is not supported on .NET 8\n#endif\n\t\t\t\t\t\t\tlabel.SetBinding(Label.TextProperty, _searchHandler.DisplayMemberName ?? \".\");\n#if NET8_0\n#pragma warning restore IL2026 // FeatureGuardAttribute is not supported on .NET 8\n#endif\n#pragma warning restore CS0618\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n#pragma warning disable CS0618\n\t\t\t\t\t\t\tif (_searchHandler.DisplayMemberName is not null)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tApplication.Current?.FindMauiContext()?.CreateLogger<ShellSearchViewAdapter>()?.LogError(TrimmerConstants.SearchHandlerDisplayMemberNameNotSupportedWarning);\n\t\t\t\t\t\t\t\tthrow new InvalidOperationException(TrimmerConstants.SearchHandlerDisplayMemberNameNotSupportedWarning);\n\t\t\t\t\t\t\t}\n#pragma warning restore CS0618\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlabel.HorizontalTextAlignment = TextAlignment.Center;\n\t\t\t\t\t\tlabel.VerticalTextAlignment = TextAlignment.Center;\n\n\t\t\t\t\t\treturn label;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn _defaultTemplate;\n\t\t\t}\n\t\t}\n\n\t\tISearchHandlerController SearchController => _searchHandler;\n\n\t\tpublic override Java.Lang.Object GetItem(int position)\n\t\t{","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSearchViewAdapter.cs#L71-L107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nSearchHandler.DisplayMemberName = \"ProductName\";\n\n// after (recommended: custom ItemTemplate)\nSearchHandler.ResultsTemplate = new DataTemplate(() =>\n{\n    var label = new Label();\n    label.SetBinding(Label.TextProperty, \"ProductName\");\n    return label;\n});\n\n// OR enable the build property (not trim-safe):\n// In .csproj: <MauiShellSearchResultsRendererDisplayMemberNameSupported>true</MauiShellSearchResultsRendererDisplayMemberNameSupported>","handlingStrategy":"validation","validationCode":"// Check before setting DisplayMemberName\nvar isSupported = AppInfo.Current?.PackageName != null; // runtime proxy\n// Simpler: use a custom ItemTemplate instead","typeGuard":"public static bool IsDisplayMemberNameSupported()\n#if MAUI_SHELL_SEARCHRESULTS_RENDERER_DISPLAYMEMBERNAME_SUPPORTED\n    => true;\n#else\n    => false;\n#endif","tryCatchPattern":null,"preventionTips":["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."],"tags":["maui","android","shell","search","trimming","nativeaot","csproj"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}