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
21.97k stars 1.72k forks source link

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

Open anpin opened 2 years ago

anpin commented 2 years ago

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
kristinx0211 commented 2 years ago

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

anpin commented 2 years ago

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

kristinx0211 commented 2 years ago

@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

anpin commented 2 years ago

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

kristinx0211 commented 2 years ago

on android 12: image dotnet info: image

anpin commented 2 years ago

on android 12: image dotnet info: image

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

anpin commented 2 years ago

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

jbe2277 commented 2 years ago

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.'

XamlTest commented 1 year ago

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] warn: 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] warn: 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
bnoffer commented 1 year ago

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.

jenscski commented 8 months ago

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

smeagol75 commented 8 months ago

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.

Vishnu473 commented 5 months ago

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

joaodarocha1 commented 5 months ago

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

EeKay commented 2 months ago

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

EeKay commented 2 months ago

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

Mark-NC001 commented 2 weeks ago

Is there any news on this? I have a major project to convert from Xamarin.Forms, and am getting this on a very basic page that simply has a ListView as it's main content - if I can't get this page to work then I've no hope for the rest of the project!!!