Skip to content

[Shell][iOS] Error when setting Shell search icon in search handler #14442

@kklose23

Description

@kklose23

Description

Null reference exception when opening app within IOS that has a Shell search with an icon set within its search handler

Steps to Reproduce

  1. Follow these steps https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/search?view=net-maui-7.0
  2. Create a constructor for the AnimalSearchHandler and set ClearIcon = "clear_icon.png"; within the constructor
  3. Run the application in an IOS simulator

Link to public reproduction project repository

N/A

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 16.2

Did you find any workaround?

Yes,

After setting ClearIcon = "clear_icon.png";, set ClearIcon.Parent = Application.Current.MainPage;

This is because source.FindMauiContext() in ShellPageRendererTracker.SetSearchBarIcon was returning null. So setting a parent element on the icon fixes it.

Relevant log output

at Microsoft.Maui.ImageSourceExtensions.GetPlatformImageAsync(IImageSource imageSource, IMauiContext mauiContext)
   at Microsoft.Maui.ImageSourceExtensions.LoadImage(IImageSource source, IMauiContext mauiContext, Action`1 finished)
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellPageRendererTracker.SetSearchBarIcon(UISearchBar searchBar, ImageSource source, UISearchBarIcon icon)
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellPageRendererTracker.AttachSearchController()
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellPageRendererTracker.set_SearchHandler(SearchHandler value)
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellPageRendererTracker.UpdateShellToMyPage()
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellPageRendererTracker.OnPageSet(Page oldPage, Page newPage)
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellPageRendererTracker.set_Page(Page value)
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.ViewDidLoad()
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions