Skip to content

MethodAccessException when using CommunityToolkit.Maui AppThemeResource with 10.0.40 #34035

@zwikk

Description

@zwikk

Description

Something is not right with the latest 10.0.40 release. After upgrading from 10.0.30 to 10.0.40, the following XAML crashes with a MethodAccessException (using CommunityToolkit.Maui 14.0.0)

<ContentPage.Resources>
  <toolkit:AppThemeColor x:Key="BgColor" Light="White" Dark="Black" />
</ContentPage.Resources>
    
<Button BackgroundColor="{toolkit:AppThemeResource BgColor}" />

See below for the complete stacktrace. This is really easy to reproduce.

Steps to Reproduce

  1. Clone repo
  2. Build and run
  3. Observe app crash

Link to public reproduction project repository

https://github.com/zwikk/maui-playground/tree/main/Source/AppThemeResourceCrash

Version with bug

10.0.40

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

10.0.30

Affected platforms

iOS, I was not able test on other platforms

Affected platform versions

Any

Did you find any workaround?

None

Relevant log output

System.MethodAccessException: Method `Microsoft.Maui.Controls.IResourcesProvider.get_IsResourcesCreated()' is inaccessible from method `CommunityToolkit.Maui.Extensions.AppThemeResourceExtension.TryFindResourceInVisualElement(object,string,object&)'
   at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.ProvideValue(Object& value, ElementNode node, Object source, XmlName propertyName)
   at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.Visit(ElementNode node, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Assembly rootAssembly, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType)
   at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[MainPage](MainPage view, Type callingType)
   at AppThemeResourceCrash.MainPage.InitializeComponent() in /Users/xx/Source/Playground/maui/maui-playground/Source/AppThemeResourceCrash/AppThemeResourceCrash/obj/Debug/net10.0-ios/iossimulator-arm64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.XamlGenerator/MainPage.xaml.sg.cs:line 20
   at AppThemeResourceCrash.MainPage..ctor() in /Users/xx/Source/Playground/maui/maui-playground/Source/AppThemeResourceCrash/AppThemeResourceCrash/MainPage.xaml.cs:line 7
   at System.Reflection.ConstructorInvoker.InterpretedInvoke(Object obj, IntPtr* args)
   at System.Reflection.ConstructorInvoker.InvokeDirectByRefWithFewArgs(Span`1 copyOfArgs)
   at System.Reflection.ConstructorInvoker.InvokeDirectByRef(Object arg1, Object arg2, Object arg3, Object arg4)
   at System.Reflection.ConstructorInvoker.InvokeImpl(Object arg1, Object arg2, Object arg3, Object arg4)
   at System.Reflection.ConstructorInvoker.Invoke(Span`1 arguments)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
   at Microsoft.Maui.Controls.ShellContent.<>c__DisplayClass20_0.<Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent>b__0()
   at Microsoft.Maui.Controls.ElementTemplate.CreateContent()
   at Microsoft.Maui.Controls.Internals.DataTemplateExtensions.CreateContent(DataTemplate self, Object item, BindableObject container)
   at Microsoft.Maui.Controls.ShellContent.Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent()
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.LoadRenderers()
   at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.ViewDidLoad()
--- End of stack trace from previous location ---
   at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle) in /Users/builder/azdo/_work/2/s/macios/src/ObjCRuntime/Runtime.cs:line 2665
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/2/s/macios/src/UIKit/UIApplication.cs:line 68
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/2/s/macios/src/UIKit/UIApplication.cs:line 100
   at AppThemeResourceCrash.Program.Main(String[] args) in /Users/xx/Source/Playground/maui/maui-playground/Source/AppThemeResourceCrash/AppThemeResourceCrash/Platforms/iOS/Program.cs:line 13

Metadata

Metadata

Assignees

No one assigned

    Labels

    t/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions