maui icon indicating copy to clipboard operation
maui copied to clipboard

System.MissingMethodException: No parameterless constructor defined for type 'Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer'

Open anpin opened this issue 2 years ago • 18 comments

Description

I've got following exceptions in a project I'm working on, so I tried to create repro with similar layout, but it doesn't throw the exception, however it doesn't show ListView items either at least on Android. In the right brown Frame is ListView bound to the same collection as CollectionView, with different DataTemplate. Screenshot_20220606-214104

Steps to Reproduce

maui-android-handler-activator-issue.zip Unpack and build!

Version with bug

6.0 Release Candidate 3

Last version that worked well

Release Candidate 1

Affected platforms

Android

Affected platform versions

Android 9

Did you find any workaround?

no

Relevant log output

[0:] [20:18:45 WRN] System.MissingMethodException: No parameterless constructor defined for type 'Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer'.
   at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Microsoft.Maui.Hosting.Internal.MauiFactory.CreateInstance(ServiceDescriptor item) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 162
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(ServiceDescriptor descriptor) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 130
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType, ServiceDescriptor single, IEnumerable`1 enumerable) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 141
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 36
   at Microsoft.Maui.Hosting.Internal.MauiHandlersFactory.GetHandler(Type type) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiHandlersFactory.cs:line 30
   at Microsoft.Maui.Controls.Compatibility.Platform.Android.Platform.CreateRenderer(VisualElement element, Context context, FragmentManager fragmentManager, LayoutInflater layoutInflater) in D:\a\_work\1\s\src\Compatibility\Core\src\Android\AppCompat\Platform.cs:line 344
[0:] [20:18:45 WRN] System.MissingMethodException: No parameterless constructor defined for type 'Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer'.
   at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Microsoft.Maui.Hosting.Internal.MauiFactory.CreateInstance(ServiceDescriptor item) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 162
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(ServiceDescriptor descriptor) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 130
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType, ServiceDescriptor single, IEnumerable`1 enumerable) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 141
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 36
   at Microsoft.Maui.Hosting.Internal.MauiHandlersFactory.GetHandler(Type type) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiHandlersFactory.cs:line 30
   at Microsoft.Maui.Controls.Compatibility.Platform.Android.Platform.CreateRenderer(VisualElement element, Context context, FragmentManager fragmentManager, LayoutInflater layoutInflater) in D:\a\_work\1\s\src\Compatibility\Core\src\Android\AppCompat\Platform.cs:line 344
[0:] [20:18:45 WRN] System.MissingMethodException: No parameterless constructor defined for type 'Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer'.
   at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Microsoft.Maui.Hosting.Internal.MauiFactory.CreateInstance(ServiceDescriptor item) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 162
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(ServiceDescriptor descriptor) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 130
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType, ServiceDescriptor single, IEnumerable`1 enumerable) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 141
   at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 36
   at Microsoft.Maui.Hosting.Internal.MauiHandlersFactory.GetHandler(Type type) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiHandlersFactory.cs:line 30
   at Microsoft.Maui.Controls.Compatibility.Platform.Android.Platform.CreateRenderer(VisualElement element, Context context, FragmentManager fragmentManager, LayoutInflater layoutInflater) in D:\a\_work\1\s\src\Compatibility\Core\src\Android\AppCompat\Platform.cs:line 344

anpin avatar Jun 06 '22 17:06 anpin

@anpin your repro project can‘t be unpacked. could you check for this and upload the correct one, thanks.

kristinx0211 avatar Jun 09 '22 07:06 kristinx0211

@kristinx0211 please try this maui-android-handler-activator-issue.zip

anpin avatar Jun 09 '22 07:06 anpin

@anpin thanks for your update, I can repro this issue on android, ListView does not show, I'm not get the exception, on windows, the ListView is showing. image

kristinx0211 avatar Jun 09 '22 09:06 kristinx0211

Here I'm running on another Android device. Can you share your Android screen shoot not Windows? What is your SDK version? Screenshot_20220609-144535

anpin avatar Jun 09 '22 10:06 anpin

on android 12: image dotnet info: image

kristinx0211 avatar Jun 10 '22 01:06 kristinx0211

on android 12: image dotnet info: image

sorry I misread your original response, thought you said you can't reproduce it on Android

anpin avatar Jun 10 '22 06:06 anpin

You can see original exception on Android if you configure logging as such in csproj use <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" /> and in MauiProgram.cs use that builder.Services.AddLogging(l => l.AddConsole());

Adjusted repro here -> maui-android-handler-activator-issue.zip

anpin avatar Jun 18 '22 07:06 anpin

I get the same exception when I want to migrate a Xamarin 5 project to MAUI. Unfortunately, this blocks me from migration to MAUI.

Used version: Visual Studio 2022 17.3.2

Starting on Android 12 results in the following exception:

System.MissingMethodException
  Message=No parameterless constructor defined for type 'Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer'.

Update: This exception is catched by the library but it shows up in log. However, my crash at startup seems to be produced by another exception. For this one I get just the following info on Android (on Windows it works):

System.InvalidCastException: 'Specified cast is not valid.'

jbe2277 avatar Sep 03 '22 14:09 jbe2277

Verified this on Visual Studio Enterprise 17.6.0 Preview 7.0. Repro on Android 13.0 with below Project: 7799.zip

image

Exception:

[DOTNET]       System.MissingMethodException: No parameterless constructor defined for type 'Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer'.
[DOTNET]          at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
[DOTNET]          at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
[DOTNET]          at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
[DOTNET]          at System.Activator.CreateInstance(Type type, Boolean nonPublic)
[DOTNET]          at System.Activator.CreateInstance(Type type)
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.CreateInstance(ServiceDescriptor item) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 162
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(ServiceDescriptor descriptor) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 130
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType, ServiceDescriptor single, IEnumerable`1 enumerable) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 141
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 36
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiHandlersFactory.GetHandler(Type type) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiHandlersFactory.cs:line 30
[DOTNET]          at Microsoft.Maui.Controls.Compatibility.Platform.Android.Platform.CreateRenderer(VisualElement element, Context context, FragmentManager fragmentManager, LayoutInflater layoutInflater) in D:\a\_work\1\s\src\Compatibility\Core\src\Android\AppCompat\Platform.cs:line 344
[Gralloc4] mapper 4.x is not supported
[DOTNET] [40m[1m[33mwarn[39m[22m[49m: Microsoft.Maui.Controls.Compatibility.Platform.Android.Platform[0]
[DOTNET]       System.MissingMethodException: No parameterless constructor defined for type 'Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer'.
[DOTNET]          at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
[DOTNET]          at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
[DOTNET]          at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
[DOTNET]          at System.Activator.CreateInstance(Type type, Boolean nonPublic)
[DOTNET]          at System.Activator.CreateInstance(Type type)
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.CreateInstance(ServiceDescriptor item) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 162
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(ServiceDescriptor descriptor) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 130
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType, ServiceDescriptor single, IEnumerable`1 enumerable) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 141
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 36
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiHandlersFactory.GetHandler(Type type) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiHandlersFactory.cs:line 30
[DOTNET]          at Microsoft.Maui.Controls.Compatibility.Platform.Android.Platform.CreateRenderer(VisualElement element, Context context, FragmentManager fragmentManager, LayoutInflater layoutInflater) in D:\a\_work\1\s\src\Compatibility\Core\src\Android\AppCompat\Platform.cs:line 344
[DOTNET] [40m[1m[33mwarn[39m[22m[49m: Microsoft.Maui.Controls.Compatibility.Platform.Android.Platform[0]
[DOTNET]       System.MissingMethodException: No parameterless constructor defined for type 'Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer'.
[DOTNET]          at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
[DOTNET]          at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
[DOTNET]          at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
[DOTNET]          at System.Activator.CreateInstance(Type type, Boolean nonPublic)
[DOTNET]          at System.Activator.CreateInstance(Type type)
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.CreateInstance(ServiceDescriptor item) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 162
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(ServiceDescriptor descriptor) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 130
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType, ServiceDescriptor single, IEnumerable`1 enumerable) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 141
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiFactory.GetService(Type serviceType) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiFactory.cs:line 36
[DOTNET]          at Microsoft.Maui.Hosting.Internal.MauiHandlersFactory.GetHandler(Type type) in D:\a\_work\1\s\src\Core\src\Hosting\Internal\MauiHandlersFactory.cs:line 30
[DOTNET]          at Microsoft.Maui.Controls.Compatibility.Platform.Android.Platform.CreateRenderer(VisualElement element, Context context, FragmentManager fragmentManager, LayoutInflater layoutInflater) in D:\a\_work\1\s\src\Compatibility\Core\src\Android\AppCompat\Platform.cs:line 344

XamlTest avatar May 15 '23 09:05 XamlTest

We were suddenly seeing this exception on CollectionView while it was wrapped in a RelativeLayout from MAUI Compatibility. We ended up refactoring the particular page and removing the RelativeLayout.

bnoffer avatar Aug 22 '23 14:08 bnoffer

Same problem here, we have a big Xamarin Forms application that we need to convert to .NET MAUI, without the compatibility layer we have to refactor ever page before release on .NET MAUI, which is probably to big task

jenscski avatar Jan 03 '24 07:01 jenscski

We are facing same problem after upgrading from Net 7 to Net 8.0.3, and the hole app is based on Relative Layouts, to be honest we are loosing time, effort and money dealing with Maui, the last thing we want to see is a compat library that stops working with a simple update.... :( I´ll try to find a workaround) Forms to Maui is really a pain.

smeagol75 avatar Jan 08 '24 15:01 smeagol75

any update on the above exception that is getting for frame renderer as i was also facing same.

Vishnu473 avatar Mar 28 '24 06:03 Vishnu473

I had a similar issue with Frames

System.MissingMethodException: 'No parameterless constructor defined for type 'Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer'.'

My workaround was to change the Frames to Borders

joaodarocha1 avatar Mar 29 '24 17:03 joaodarocha1

any updates? Noticing this on a client's project that I'm upgrading. also using compatibility mode and RelativeLayout with a ListView

EeKay avatar Jul 04 '24 14:07 EeKay

I've resolved this by using a Grid implementation. Though, it might be good to reference this issue for people currently in the migration phase towards MAUI

EeKay avatar Jul 04 '24 19:07 EeKay