{"record":{"id":"d9327ad975733d15","repo":"dotnet/maui","slug":"displaymembername-is-not-supported-consider-imple-d9327a","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/iOS/ShellSearchResultsRenderer.cs","lineNumber":60,"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<ShellSearchResultsRenderer>()?.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\n\t\t\t\t\t\t\tlabel.SetBinding(Label.TextProperty, static (object o) => o);\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}\n\t\t}\n\n\t\tpublic event EventHandler<object> ItemSelected;\n\n\t\tpublic ShellSearchResultsRenderer(IShellContext context)\n\t\t{","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSearchResultsRenderer.cs#L42-L78","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Replace DisplayMemberName with a custom ItemTemplate that explicitly binds the display property.","Enable the build property if trim-safety is not a concern: add `<MauiShellSearchResultsRendererDisplayMemberNameSupported>true</MauiShellSearchResultsRendererDisplayMemberNameSupported>` to .csproj.","Remove the DisplayMemberName assignment entirely and use explicit DataTemplate bindings."],"exampleFix":"// before\nSearchHandler.DisplayMemberName = \"Title\";\n\n// after — custom ItemTemplate (trim-safe)\nSearchHandler.ResultsTemplate = new DataTemplate(() =>\n{\n    var label = new Label();\n    label.SetBinding(Label.TextProperty, \"Title\");\n    return label;\n});\n\n// OR enable in .csproj (not trim-safe):\n// <MauiShellSearchResultsRendererDisplayMemberNameSupported>true</MauiShellSearchResultsRendererDisplayMemberNameSupported>","handlingStrategy":"validation","validationCode":"// Use ItemTemplate instead of DisplayMemberName\n// Before setting DisplayMemberName, check build support at compile time\n#if !MAUI_SHELL_SEARCHRESULTS_RENDERER_DISPLAYMEMBERNAME_SUPPORTED\n// Do not set DisplayMemberName — use ItemTemplate\n#endif","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 iOS code.","Enable the MSBuild property only if trim/NativeAOT is not a target.","Flag DisplayMemberName usage in code review for non-trimmed builds."],"tags":["maui","ios","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"}