0

I'm getting an exception when trying to open a Page View that uses any CommunityToolkit.Maui view/control.

I am building the app with .Net MAUI 10 <MauiVersion>10.0.10</MauiVersion>.

I have included UseMauiCommunityToolkit() in MauiProgram:

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
            .UseMauiApp<App>()
            .RegisterFirebaseServices()
            .UseUraniumUIMaterial()
            .UseUraniumUI()
            .UseMicrocharts()
            .UseMaterialComponents()
            .UseMauiCommunityToolkit()
}

And I have the following dependencies:

        <PackageReference Include="Duende.IdentityModel" Version="8.0.0-rc.1" />
        <PackageReference Include="Microcharts.Maui" Version="1.0.1" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.0" />
        <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.14.0" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
        <PackageReference Include="NodaTime" Version="3.2.2" />
        <PackageReference Include="PINView.MAUI" Version="1.0.2" />
        <PackageReference Include="Plugin.Firebase" Version="3.1.4" />
        <PackageReference Include="Plugin.Firebase.Crashlytics" Version="3.1.1" />
        <PackageReference Include="Plugin.InAppBilling" Version="9.1.0" />
        <PackageReference Include="SkiaSharp" Version="3.119.1" />
        <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
        <PackageReference Include="UraniumUI.Material" Version="2.13.0" />
        <PackageReference Include="Microsoft.Maui.Controls" Version="10.0.10" />
        <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="10.0.10" />
        <PackageReference Include="Microsoft.Maui.Essentials" Version="10.0.10" />
        <PackageReference Include="CommunityToolkit.Maui" Version="13.0.0" />
        <PackageReference Include="Material.Components.Maui" Version="0.2.2-preview" />
        <PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
        <PackageReference Include="Xamarin.GooglePlayServices.Base" Version="118.9.0" />

HomePage.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:d="http://schemas.microsoft.com/dotnet/2021/maui/design"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    xmlns:toolkitViews="clr-namespace:CommunityToolkit.Maui.Views;assembly=CommunityToolkit.Maui"
    xmlns:converter="clr-namespace:MyProject.Views.Converters"
    xmlns:microcharts="clr-namespace:Microcharts.Maui;assembly=Microcharts.Maui"
    xmlns:enum="clr-namespace:MyProject.Models;assembly=MyProject"
    xmlns:material="http://schemas.enisn-projects.io/dotnet/maui/uraniumui/material"
    xmlns:maui="clr-namespace:Material.Components.Maui;assembly=Material.Components.Maui"
    x:Class="MyProject.Views.HomePage"
    xmlns:viewModels="clr-namespace:MyProject.ViewModels"
    x:DataType="viewModels:HomeViewModel"
    mc:Ignorable="d"
    BackgroundColor="{StaticResource Primary}"
>
    <Shell.TitleView>
        <StackLayout Orientation="Horizontal">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1*"></ColumnDefinition>
                    <ColumnDefinition Width="10*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
            </Grid>

            <AbsoluteLayout VerticalOptions="Center" Margin="0, 0, 5, 0">
                <toolkitViews:AvatarView WidthRequest="30" HeightRequest="30" Text="{Binding UserName}" />
                <ImageButton Clicked="ShowProfile" BackgroundColor="Transparent" WidthRequest="30" HeightRequest="30" CornerRadius="15" />
            </AbsoluteLayout>
            <Label VerticalOptions="Center" FontSize="Title" TextColor="White" Text="Home" />
        </StackLayout>
    </Shell.TitleView>

HomePage.xaml.cs:

public partial class HomePage
{
    public HomePage(HomeViewModel vm)
    {
        InitializeComponent();
        BindingContext = vm;
    }
}

And finally the exception:

Microsoft.Maui.Controls.Xaml.XamlParseException: Position 30:18. Arg_NoDefCTor, CommunityToolkit.Maui.Views.AvatarView
 ---> System.MissingMethodException: Arg_NoDefCTor, CommunityToolkit.Maui.Views.AvatarView
   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.Controls.Xaml.CreateValuesVisitor.Visit(ElementNode node, INode parentNode) in /_/src/Controls/src/Xaml/CreateValuesVisitor.cs:line 113
   Exception_EndOfInnerExceptionStack
   at Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.Visit(ElementNode node, INode parentNode) in /_/src/Controls/src/Xaml/CreateValuesVisitor.cs:line 121
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) in /_/src/Controls/src/Xaml/XamlNode.cs:line 128
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) in /_/src/Controls/src/Xaml/XamlNode.cs:line 124
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) in /_/src/Controls/src/Xaml/XamlNode.cs:line 124
   at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode) in /_/src/Controls/src/Xaml/XamlNode.cs:line 175
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, Boolean useDesignProperties) in /_/src/Controls/src/Xaml/XamlLoader.cs:line 233
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Assembly rootAssembly, Boolean useDesignProperties) in /_/src/Controls/src/Xaml/XamlLoader.cs:line 103
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties) in /_/src/Controls/src/Xaml/XamlLoader.cs:line 57
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType) in /_/src/Controls/src/Xaml/XamlLoader.cs:line 53
   at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[HomePage](HomePage view, Type callingType) in /_/src/Controls/src/Xaml/ViewExtensions.cs:line 42
   at MyProject.Views.HomePage.InitializeComponent() in /Users/me/Projects/MyProject/obj/Debug/net10.0-android/android-arm64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.XamlGenerator/Views_HomePage.xaml.sg.cs:line 34
   at MyProject.Views.HomePage..ctor(HomeViewModel vm) in /Users/me/Projects/MyProject/Views/HomePage.xaml.cs:line 11
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Constructor(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeServiceProviderEngine.<>c__DisplayClass4_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType) in /_/src/Core/src/MauiContext.cs:line 87
   at Microsoft.Maui.Controls.ShellContent.<>c__DisplayClass20_0.<Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent>b__0() in /_/src/Controls/src/Core/Shell/ShellContent.cs:line 78
   at Microsoft.Maui.Controls.ElementTemplate.CreateContent() in /_/src/Controls/src/Core/ElementTemplate.cs:line 87
   at Microsoft.Maui.Controls.Internals.DataTemplateExtensions.CreateContent(DataTemplate self, Object item, BindableObject container) in /_/src/Controls/src/Core/DataTemplateExtensions.cs:line 23
   at Microsoft.Maui.Controls.ShellContent.Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent() in /_/src/Controls/src/Core/Shell/ShellContent.cs:line 91
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) in /_/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs:line 130
   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\net10.0-android\generated\src\AndroidX.Fragment.App.Fragment.cs:line 2420
4
  • Looking at this. They just use the xmlns:toolkit=... not xmlns:toolkitViews... - Try that? Commented yesterday
  • Hi @Lewie, I've tried that as well, but it doesn't work. Commented yesterday
  • Might be useful to know that the code works in .NET MAUI 8. It's only after upgrading to .NET 10 and updating the nuget packages, that I'm facing this issue. Commented yesterday
  • 1
    Yeah I was trying to see if they had mentioned it works along side .NET 10. You're code is correct according to docs. I would have a look on CommunityToolkit GitHub - It could be that something is broke in .NET 10 and could be reported already. Commented yesterday

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.