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.24k stars 1.76k forks source link

Microsoft.Maui.Platform.HandlerNotFoundException : Handler not found for view Microsoft.Maui.Controls.Maps.Map. #12320

Closed nmdaraniya closed 1 year ago

nmdaraniya commented 1 year ago

I have below code in my NewPage1.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:test="clr-namespace:Microsoft.Maui.Maps;assembly=Microsoft.Maui.Maps"
             x:Class="MauiApp1_Sample.NewPage1"
             Title="NewPage1"
             xmlns:maps="clr-namespace:Microsoft.Maui.Controls.Maps;assembly=Microsoft.Maui.Controls.Maps"
             xmlns:sensors="clr-namespace:Microsoft.Maui.Devices.Sensors;assembly=Microsoft.Maui.Essentials">
    <VerticalStackLayout>
        <Label 
            Text="Welcome to .NET MAUI! New Page 1"
            VerticalOptions="Center" 
            HorizontalOptions="Center" />

        <Button
                x:Name="btnNewPage2"
                Text="Open New Page 2"
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="btnNewPage2_Clicked"
                HorizontalOptions="Center" />

        <maps:Map>
            <x:Arguments>
                <test:MapSpan>
                    <x:Arguments>
                        <sensors:Location>
                            <x:Arguments>
                                <x:Double>36.9628066</x:Double>
                                <x:Double>-122.0194722</x:Double>
                            </x:Arguments>
                        </sensors:Location>
                        <x:Double>0.01</x:Double>
                        <x:Double>0.01</x:Double>
                    </x:Arguments>
                </test:MapSpan>
            </x:Arguments>
        </maps:Map>
    </VerticalStackLayout>
</ContentPage>

When I am trying to run my application its throwing below error,

Microsoft.Maui.Platform.HandlerNotFoundException
  Message=Handler not found for view Microsoft.Maui.Controls.Maps.Map.
  Source=Microsoft.Maui
  StackTrace:
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 92
   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.Handlers.LayoutHandler.SetVirtualView(IView view) in D:\a\_work\1\s\src\Core\src\Handlers\Layout\LayoutHandler.Android.cs:line 43
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 56
   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.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.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler handler) in D:\a\_work\1\s\src\Core\src\Handlers\ContentView\ContentViewHandler.Android.cs:line 44
   at Microsoft.Maui.Handlers.ContentViewHandler.MapContent(IContentViewHandler handler, IContentView page) in D:\a\_work\1\s\src\Core\src\Handlers\ContentView\ContentViewHandler.Android.cs:line 49
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IContentViewHandler, 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.Handlers.ViewHandler.SetVirtualView(IElement element) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandler.cs:line 125
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 53
   at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView view) in D:\a\_work\1\s\src\Core\src\Handlers\ContentView\ContentViewHandler.Android.cs:line 27
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 56
   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.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.ViewExtensions.ToHandler(IView view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ViewExtensions.cs:line 43
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellContentFragment.OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellContentFragment.cs:line 145
   at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_inflater, IntPtr native_container, IntPtr native_savedInstanceState) in C:\a\_work\1\s\generated\androidx.fragment.fragment\obj\Release\net6.0-android\generated\src\AndroidX.Fragment.App.Fragment.cs:line 1999
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L(_JniMarshal_PPLLL_L callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1, IntPtr p2) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 352
Eilon commented 1 year ago

I suspect you need to add a call to UseMauiMaps() in your app's MauiProgram.cs file, like this:

https://github.com/dotnet/maui/blob/main/src/Controls/samples/Controls.Sample.Sandbox/MauiProgram.cs#LL13C9-L13C9

ghost commented 1 year ago

Hi @nmdaraniya. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost commented 1 year ago

Hi @nmdaraniya. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

nmdaraniya commented 1 year ago

I have tried your steps by calling to UseMauiMaps() in your app's MauiProgram.cs file, but still issue is not resolved, i have attached my demo project git repository link , from this demo project you can regenerate the issue. https://github.com/nmdaraniya/Map_Demo_MAUI.git

andyfmking commented 1 year ago

I have tried your steps by calling to UseMauiMaps() in your app's MauiProgram.cs file, but still issue is not resolved, i have attached my demo project git repository link , from this demo project you can regenerate the issue. https://github.com/nmdaraniya/Map_Demo_MAUI.git

Observed the same behavior in iOS

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

GopiMtp commented 1 year ago

I've been facing the same issue when debugging in andriod as well. I just followed the same set of instructions given in the map documentation [https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/map?view=net-maui-7.0](Maps Documentation)

Here is the debug logs for your information

[eword.phonewor] Explicit concurrent copying GC freed 13956(811KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 3546KB/7092KB, paused 393us total 7.696ms [OpenGLRenderer] endAllActiveAnimators on 0x7d1e51ec3720 (RippleDrawable) with handle 0x7d1d72ab7f10 Resolved pending breakpoint at 'HomeViewModel.cs:47,1' to void Phoneword.ViewModels.HomeViewModel.d__4.MoveNext () [0x0000f]. [Choreographer] Skipped 119 frames! The application may be doing too much work on its main thread. [OpenGLRenderer] Davey! duration=2006ms; Flags=0, IntendedVsync=120755745426103, Vsync=120757728759357, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=120757743958000, AnimationStart=120757743982100, PerformTraversalsStart=120757744112400, DrawStart=120757746117300, SyncQueued=120757749313500, SyncStart=120757750262600, IssueDrawCommandsStart=120757750324000, SwapBuffers=120757750908800, FrameCompleted=120757752766100, DequeueBufferDuration=861900, QueueBufferDuration=522200, GpuCompleted=-4813848412547562665, Microsoft.Maui.Platform.HandlerNotFoundException: 'Handler not found for view Microsoft.Maui.Controls.Maps.Map.'

Microsoft.Maui.Platform.HandlerNotFoundException: 'Handler not found for view Microsoft.Maui.Controls.Maps.Map.'

[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: Microsoft.Maui.Platform.HandlerNotFoundException: Handler not found for view Microsoft.Maui.Controls.Maps.Map. [mono-rt] at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) in D:\a_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 92 [mono-rt] at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) in D:\a_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 127 [mono-rt] at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view) in D:\a_work\1\s\src\Core\src\Handlers\Layout\LayoutHandler.Android.cs:line 43 [mono-rt] at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 56 [mono-rt] 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 [mono-rt] 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 [mono-rt] 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 [mono-rt] at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 96 [mono-rt] at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) in D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 127 [mono-rt] at Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler handler) in D:\a\_work\1\s\src\Core\src\Handlers\ContentView\ContentViewHandler.Android.cs:line 44 [mono-rt] at Microsoft.Maui.Handlers.ContentViewHandler.MapContent(IContentViewHandler handler, IContentView page) in D:\a\_work\1\s\src\Core\src\Handlers\ContentView\ContentViewHandler.Android.cs:line 49 [mono-rt] at Microsoft.Maui.PropertyMapper2.<>cDisplayClass5_0[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IContentViewHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].b__0(IElementHandler h, IElement v) in D:\a_work\1\s\src\Core\src\PropertyMapper.cs:line 183 [mono-rt] at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) in D:\a_work\1\s\src\Core\src\PropertyMapper.cs:line 47 [mono-rt] at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) in D:\a_work\1\s\src\Core\src\PropertyMapper.cs:line 82 [mono-rt] at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) in D:\a_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:line 74 [mono-rt] at Microsoft.Maui.Handlers.ViewHandler.SetVirtualView(IElement element) in D:\a_work\1\s\src\Core\src\Handlers\View\ViewHandler.cs:line 125 [mono-rt] at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view) in D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 53 [mono-rt] at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView view) in D:\a\_work\1\s\src\Core\src\Handlers\ContentView\ContentViewHandler.Android.cs:line 27 [mono-rt] at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentViewGroup, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) in D:\a_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:line 56 [mono-rt] 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 [mono-rt] 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 [mono-rt] 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 [mono-rt] at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) in D:\a_work\1\s\src\Core\src\Platform\ElementExtensions.cs:line 96 [mono-rt] at Microsoft.Maui.Platform.ViewExtensions.ToHandler(IView view, IMauiContext context) in D:\a_work\1\s\src\Core\src\Platform\ViewExtensions.cs:line 43 [mono-rt] at Microsoft.Maui.Controls.Platform.Compatibility.ShellContentFragment.OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) in D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellContentFragment.cs:line 145 [mono-rt] at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_osBundle(IntPtr jnienv, IntPtr nativethis, IntPtr native_inflater, IntPtr native_container, IntPtr native_savedInstanceState) in C:\a_work\1\s\generated\androidx.fragment.fragment\obj\Release et6.0-android\generated\src\AndroidX.Fragment.App.Fragment.cs:line 1999 [mono-rt] at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L(_JniMarshal_PPLLL_L callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1, IntPtr p2) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 352 [HostConnection] HostConnection::get() New Host Connection established 0x7d1de1e8f550, tid 26828 [HostConnection] HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_2

isnel85 commented 1 year ago

Any news of fixing this bug, I'm seeing the same error in my project, this is the log in case you need it:

Microsoft.Maui.Platform.HandlerNotFoundException: Handler not found for view Microsoft.Maui.Controls.Maps.Map. at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler handler) at Microsoft.Maui.Handlers.ContentViewHandler.MapContent(IContentViewHandler handler, IContentView page) at Microsoft.Maui.PropertyMapper2.<>c__DisplayClass5_0[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IContentViewHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view) at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ViewExtensions.ToHandler(IView view, IMauiContext context) at Microsoft.Maui.Controls.Handlers.Items.TemplateHelpers.GetHandler(View view, IMauiContext context) at Microsoft.Maui.Controls.Handlers.Items.TemplatedCell.Bind(DataTemplate template, Object bindingContext, ItemsView itemsView) at Microsoft.Maui.Controls.Handlers.Items.ItemsViewController1[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].UpdateTemplatedCell(TemplatedCell cell, NSIndexPath indexPath) at Microsoft.Maui.Controls.Handlers.Items.ItemsViewController1[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].CreateMeasurementCell(NSIndexPath indexPath) at Microsoft.Maui.Controls.Handlers.Items.ItemsViewController1[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetPrototype() at Microsoft.Maui.Controls.Handlers.Items.ItemsViewLayout.DetermineCellSize() at Microsoft.Maui.Controls.Handlers.Items.ListViewLayout.ConstrainTo(CGSize size) at Microsoft.Maui.Controls.Handlers.Items.ItemsViewController1[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].CheckForEmptySource() at Microsoft.Maui.Controls.Handlers.Items.ItemsViewController1[[Microsoft.Maui.Controls.ReorderableItemsView, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].NumberOfSections(UICollectionView collectionView) at UIKit.UICollectionViewLayout.PrepareLayout() at Microsoft.Maui.Controls.Handlers.Items.ItemsViewLayout.PrepareLayout() at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)

Eilon commented 1 year ago

Just a guess, but one of the repro apps seems to be mixing .NET 6 and .NET 7 in the same app.

For example, in https://github.com/nmdaraniya/Map_Demo_MAUI it's using .NET 6 as the target framework: https://github.com/nmdaraniya/Map_Demo_MAUI/blob/master/Map_Demo_MAUI/Map_Demo_MAUI.csproj#L4

But it's using the .NET 7 version of the Maps control: https://github.com/nmdaraniya/Map_Demo_MAUI/blob/master/Map_Demo_MAUI/Map_Demo_MAUI.csproj#L52

Mixing versions like that is not recommended. There was no .NET 6 version of the Maps control, so I suggest trying to update the whole app to .NET 7 and then trying again.

isnel85 commented 1 year ago

In my case the issue was because i was using a prerelease version (8.0.0-preview.1.7762) when I replaced it for the Microsoft.Maui.Controls.Maps.7.0.59 everything start working as expected.

Eilon commented 1 year ago

In my case the issue was because i was using a prerelease version (8.0.0-preview.1.7762) when I replaced it for the Microsoft.Maui.Controls.Maps.7.0.59 everything start working as expected.

Great, I'm glad you got it working! We call this situation "crossing the streams" (mixing major versions of things), and it's never a good idea, but it's easy to do by accident!

image

ragiovan commented 1 year ago

I had the same preview version - it doesn't help that that's the default option when installing the nuget package.

Eilon commented 1 year ago

I had the same preview version - it doesn't help that that's the default option when installing the nuget package.

Understood and agreed. Unfortunately there's no way in NuGet packages to specify the precise rules governing how each package can be used. This is a case where theoretically it could work, but in practice it doesn't (apparently).

foxynanre22 commented 1 year ago

In my case the issue was because i was using a prerelease version (8.0.0-preview.1.7762) when I replaced it for the Microsoft.Maui.Controls.Maps.7.0.59 everything start working as expected.

I have the same version (7.0.59) and still have this problem :(

Locxion commented 1 year ago

Still a Problem on version 7.0.8.1

imaziofa commented 1 year ago

I have tried 7.0.59 and its still giving the same error

tcudjoe commented 1 year ago

This was my problem and also my solution!

The android target runtime was set to .net 6. Changed it to .net 7 and it works just in time for my school assesment :)

Eilon commented 1 year ago

For anyone running into issues like this, please read my comment here: https://github.com/dotnet/maui/issues/12320#issuecomment-1466450487

If you are still experiencing this problem, please post the contents of your CSPROJ file (so we can check the versions of everything), and your MauiProgram.cs file (so we can check the relevant startup code). You can omit any private or sensitive data.

Jimmmbo90 commented 1 year ago

Don´t know why but bumping up the min supported ios version to 14.2 in the csproj file "fixed" the issue for me.

ghost commented 1 year ago

Hi @nmdaraniya. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

jinxinjuan commented 1 year ago

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 3.0(net8). Not repro on Android platform with sample project. https://github.com/nmdaraniya/Map_Demo_MAUI

K-Ketchup commented 1 year ago

Still have this problem with the latest version and other versions mentioned here (i.e., 7.0.49, 7.0.59) - is there still no fix?

.csproj file

net7.0-android;net7.0-ios;net7.0-maccatalyst $(TargetFrameworks);net7.0-windows10.0.19041.0 Exe Dook true true enable Dook com.companyname.dook df624700-6076-464b-a86b-342cf5c9b7fd 1.0 1 14.2 13.1 21.0 10.0.17763.0 10.0.17763.0 6.5 Apple Development: Created via API (B7SWNU67LT) VS: WildCard Development None True True None MauiProgram.cs ``` using Microsoft.Extensions.Logging; namespace Dook; public static class MauiProgram { public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() .UseMauiMaps() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }); #if DEBUG builder.Logging.AddDebug(); #endif return builder.Build(); } } ```
Eilon commented 1 year ago

@K-Ketchup in your CSPROJ file it looks like there's a mix of .NET 8 and .NET 7 versions.

This is using .NET 7 (net7-XYZ):

    <TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>

And this is using a mix of 7.0-XYZ and 8.0-XYZ:

<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0-preview.7.23375.6" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0-preview.7.23375.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0-preview.7.23375.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0-preview.7.23375.6" />
<PackageReference Include="Microsoft.Maui.Controls.Maps" Version="7.0.49" />

I'm not sure if it's the cause of the problem you're seeing, but I wouldn't expect it to work.

Also, can you confirm you're seeing the exact same error?

K-Ketchup commented 1 year ago

Sorry about that, it seems like my error itself is different from the one mentioned here. I did try fixing the package versions but that didn't seem to work. I presume this is an issue with the Microsoft.Maui.Controls.Maps nuget package since I had trouble declaring it as a namespace at the top of my main view.

[0:] An error occurred: 'Handler not found for view Microsoft.Maui.Controls.Maps.Map.'. Callstack: '   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
   at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view)
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
   at Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler handler)
   at Microsoft.Maui.Handlers.ContentViewHandler.MapContent(IContentViewHandler handler, IContentView page)
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IContentViewHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view)
   at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView view)
   at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
   at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
   at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
   at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
   at Microsoft.Maui.Platform.ViewExtensions.ToHandler(IView view, IMauiContext context)
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.SetPageRenderer(Page page, ShellContent shellContent)
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.LoadRenderers()
   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)
   at Dook.Program.Main(String[] args) in C:\Users\yoboi\source\repos\Dook\Platforms\iOS\Program.cs:line 13
   at System.Reflection.MethodInvoker.InterpretedInvoke(Object obj, Span`1 args, BindingFlags invokeAttr)'
The app has been terminated.
Eilon commented 1 year ago

@K-Ketchup does it work in a brand new MAUI app that you create from scratch? If nothing works, please upload a simple repro app to a public GitHub repo and we can take a look. I'm pretty sure the Maps package is working for most people so we'll have to see what's different in your project. Thanks!

K-Ketchup commented 1 year ago

I've found a fix. The MauiProgram.cs file seemed to be the issue.

Changed the file from

using Microsoft.Extensions.Logging;

namespace Dook;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .UseMauiMaps()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });

#if DEBUG
        builder.Logging.AddDebug();
#endif

        return builder.Build();
    }
}

To

using Microsoft.Extensions.Logging;

namespace Dook
{
    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                })
                .UseMauiMaps();

        #if DEBUG
            builder.Logging.AddDebug();
        #endif

            return builder.Build();
        }
    }
}
Eilon commented 1 year ago

@K-Ketchup : Interesting - so calling UseMauiMaps() after ConfigureFonts() is what fixed it? That sounds like it could be a bug.

I filed https://github.com/dotnet/maui/issues/16736 to track that.