dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.01k stars 1.72k forks source link

Null Argument Exception for at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.OnToolbarPropertyChanged(Object sender, PropertyChangedEventArgs e) #16686

Open GonCord opened 1 year ago

GonCord commented 1 year ago

Description

Same Error message as per closed bug: https://github.com/dotnet/maui/issues/11277 (in Mac) Also same as bug: https://github.com/dotnet/maui/issues/10384

Direct link to repository: TestShareApp

App crashes when sharing a file (image) from another App.

Exception seems to originate at the Base from OnCreate(Bundle savedInstanceState)

With Message and Stack: image

I'm running the code on Platforms.Android.MainActivity.cs with standard [Activity] and [Intent]

image

I didn't touch Platforms.Android.AndroidManifest.xml image

Steps to Reproduce

  1. Create a File -> New Project MAUI app
  2. Add the following attribute to the MainActivity class: [IntentFilter(new[] { Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "image/*")]
  3. Override method OnCreate(Bundle savedInstanceState)
  4. Make sure that base.OnCreate(savedInstanceState) is present
  5. Build App in Debug Mode (I'm using Pixel 5 - API 33 (Android 13.0 API 33)
  6. Minimize the app, go to any app that shares images (file explorer, or the browser)
  7. Share any image to the new app

Expected outcome: The app should finish calling OnCreate() successfully Actual outcome: The app crashes during OnCreate()

Additional notes: You can actually get the Intent and the extras off of it, but the crash will still happen afterwards when base.OnCreate() is called (which can't be skipped).

Link to public reproduction project repository

https://github.com/GonCord/TestShareApp/tree/master

Version with bug

7.0.92

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 13

Did you find any workaround?

no workaround found

Relevant log output

at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.OnToolbarPropertyChanged(Object sender, PropertyChangedEventArgs e) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellToolbarTracker.cs:line 581
   at Microsoft.Maui.Controls.Toolbar.SetProperty[IEnumerable`1](IEnumerable`1& backingStore, IEnumerable`1 value, String propertyName) in D:\a\_work\1\s\src\Controls\src\Core\Toolbar.cs:line 74
   at Microsoft.Maui.Controls.Toolbar.set_ToolbarItems(IEnumerable`1 value) in D:\a\_work\1\s\src\Controls\src\Core\Toolbar.cs:line 34
   at Microsoft.Maui.Controls.ShellToolbar.ApplyChanges() in D:\a\_work\1\s\src\Controls\src\Core\ShellToolbar.cs:line 84
   at Microsoft.Maui.Controls.ShellToolbar.<.ctor>b__8_2(Object _, EventArgs __) in D:\a\_work\1\s\src\Controls\src\Core\ShellToolbar.cs:line 44
   at Microsoft.Maui.Controls.Element.OnHandlerChangedCore() in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:line 32
   at Microsoft.Maui.Controls.VisualElement.OnHandlerChangedCore() in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\VisualElement\VisualElement.Impl.cs:line 40
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:line 65
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:line 19
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\VisualElement\VisualElement.Impl.cs:line 294
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 96
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 127
   at Microsoft.Maui.Platform.ContainerView.SetView(IElement view, Boolean forceRefresh) in D:\a\_work\1\s\src\Core\src\Platform\Android\ContainerView.cs:line 72
   at Microsoft.Maui.Platform.ContainerView.set_CurrentView(IElement value) in D:\a\_work\1\s\src\Core\src\Platform\Android\ContainerView.cs:line 51
   at Microsoft.Maui.Platform.ElementExtensions.ToContainerView(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\Android\ElementExtensions.cs:line 11
   at Microsoft.Maui.Platform.NavigationRootManager.Connect(IView view, IMauiContext mauiContext) in D:\a\_work\1\s\src\Core\src\Platform\Android\Navigation\NavigationRootManager.cs:line 51
   at Microsoft.Maui.Handlers.WindowHandler.CreateRootViewFromContent(IWindowHandler handler, IWindow window) in D:\a\_work\1\s\src\Core\src\Handlers\Window\WindowHandler.Android.cs:line 38
   at Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window) in D:\a\_work\1\s\src\Core\src\Handlers\Window\WindowHandler.Android.cs:line 16
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IWindow, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IWindowHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 183
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 47
   at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 82
   at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) in D:\a\_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:line 74
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:line 63
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Element\Element.Impl.cs:line 19
   at Microsoft.Maui.Platform.ElementExtensions.SetHandler(Context nativeElement, IElement element, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 156
   at Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler(Activity platformWindow, IWindow window, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 166
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Activity activity, IApplication application, Bundle savedInstanceState) in D:\a\_work\1\s\src\Core\src\Platform\Android\ApplicationExtensions.cs:line 46
   at Microsoft.Maui.MauiAppCompatActivity.OnCreate(Bundle savedInstanceState) in D:\a\_work\1\s\src\Core\src\Platform\Android\MauiAppCompatActivity.cs:line 32
   at TestShareApp.MainActivity.OnCreate(Bundle savedInstanceState) in D:\00 - DEV\MauiTestShareApp-main\TestShareApp\Platforms\Android\MainActivity.cs:line 18

Source: Microsoft.Maui.Controls
Declaring Type: ShellToolbarTracker
TargetSite: OnToolbarPropertyChanged
ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.8.0 Preview 1.0. Repro on Android 13.0-API33 .NET 8 with below Project: TestShareApp.zip

GonCord commented 10 months ago

Dear All,

Any updates on this bug? thanks!