Closed devonuto closed 2 years ago
You have to register your pages in DI.
builder.Services.AddSingleton<DashboardPage>();
It is registered in the shell itself.
Routing.RegisterRoute(nameof(DashboardPage), typeof(DashboardPage));
Didn't think it needed to be in the DI as well, as it works without MVVM. It's complaining that there is no parameterless path, because it's not parameterless in the MVVM model.
I had abandoned this method, and is now affected by https://github.com/xamarin/XamarinCommunityToolkit/issues/1842 after the latest VS updates.
That is not enough to register it in shell route. See example from HackerNews: https://github.com/brminnick/HackerNews/blob/main/src/HackerNews/MauiProgram.cs#35
By the way, what features from Xamarin Community Toolkit do you use? Can you migrate to CommunityToolkit.Maui?
I am using the Maui toolkit, but I'm getting that same bug, so I assume it's the same issue.
"CommunityToolkit.Maui" Version="1.0.0-pre9" "CommunityToolkit.Maui.Markup" Version="1.0.0-pre9" "CommunityToolkit.Mvvm" Version="8.0.0-preview3"
Hmm. I noticed I still had my old Xamarin app still sitting unused in the sln , but it wasn't part of the build. I removed it from the sln and it's not happening anymore. Will try the above again.
Description
When following the method shown in https://github.com/brminnick/HackerNews, when calling the page from Shell, results in a "System.MissingMethodException: 'No parameterless constructor defined for type DashboardPage" error under Android or just an unhandled Win32 error on Windows.
Steps to Reproduce
public AppShell() { Items.Add( new FlyoutItem { Title = "News", Route = nameof(NewsPage), Items.Add( new Tab { Title = "News", Items = { new ShellContent { Title = "News", Route = nameof(NewsPage), ContentTemplate = new DataTemplate(typeof(NewsPage)), } } } ) } ); }
Version with bug
Preview 14
Last version that worked well
Unknown/Other
Affected platforms
Android, Windows, I was not able test on other platforms
Affected platform versions
net6.0-android 21.0, Windows 10.0.17763.0
Did you find any workaround?
Not use this MVVM method
Relevant log output
No response