Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] AppThemeResourceExtension throws exception in Release after updating community toolkit version to 10.0.0 #2415

Open
2 tasks done
DooNeGo opened this issue Dec 26, 2024 · 1 comment
Labels
bug Something isn't working unverified

Comments

@DooNeGo
Copy link

DooNeGo commented Dec 26, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

AppThemeResourceExtension throws an exception during initialization on all platforms in Release mode. In Debug, it works as expected.

If the line with AppThemeResource is removed, no exception will be thrown.

<ContentPage
    x:Class="MauiApp1.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    BackgroundColor="{toolkit:AppThemeResource PageBackgroundColor}">
<toolkit:AppThemeColor
    x:Key="PageBackgroundColor"
    Dark="#000000"
    Light="#f0f0f6" />

Android Emulator exception

FATAL EXCEPTION: main
Process: com.companyname.mauiapp1, PID: 5745
android.runtime.JavaProxyThrowable: [System.ArgumentException]: Arg_ArgumentException Arg_ParamName_Name, serviceProvider
at CommunityToolkit.Maui.Extensions.AppThemeResourceExtension.ProvideValue + 0x39(Unknown Source)
at MauiApp1.MainPage.InitializeComponent + 0xca(Unknown Source)
at MauiApp1.MainPage..ctor + 0x6(Unknown Source)
at Unknown.Unknown(Unknown Source)
at System.Reflection.ConstructorInvoker.InterpretedInvoke + 0x0(Unknown Source)
at System.Reflection.ConstructorInvoker.InvokeDirectByRefWithFewArgs + 0x7d(Unknown Source)
at System.Reflection.ConstructorInvoker.InvokeDirectByRef + 0x29(Unknown Source)
at System.Reflection.ConstructorInvoker.InvokeImpl + 0xbe(Unknown Source)
at System.Reflection.ConstructorInvoker.Invoke + 0x47(Unknown Source)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities+ConstructorMatcher.CreateInstance + 0xc8(Unknown Source)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance + 0x1d7(Unknown Source)
at Microsoft.Maui.Controls.ShellContent+<>c__DisplayClass20_0.<Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent>b__0 + 0x68(Unknown Source)
at Microsoft.Maui.Controls.ElementTemplate.CreateContent + 0x27(Unknown Source)
at Microsoft.Maui.Controls.Internals.DataTemplateExtensions.CreateContent + 0x8(Unknown Source)
at Microsoft.Maui.Controls.ShellContent.Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent + 0x69(Unknown Source)
at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.OnCreateView + 0x16e(Unknown Source)
at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ + 0x20(Unknown Source)
at Unknown.Unknown(Unknown Source)
at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L + 0x5(Unknown Source)
at crc640ec207abc449b2ca.ShellSectionRenderer.n_onCreateView(Native Method)
at crc640ec207abc449b2ca.ShellSectionRenderer.onCreateView(ShellSectionRenderer.java:41)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:3119)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:577)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:286)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2164)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2065)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3277)
at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:3180)
at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3153)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:608)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:286)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2164)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2065)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3277)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3187)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:263)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:350)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:251)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1582)
at android.app.Activity.performStart(Activity.java:8628)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3807)

iOS Simulator exception

Unhandled Exception:
System.ArgumentException: Arg_ArgumentException Arg_ParamName_Name, serviceProvider
   at CommunityToolkit.Maui.Extensions.AppThemeResourceExtension.ProvideValue(IServiceProvider serviceProvider)
   at MauiApp1.MainPage.InitializeComponent()
   at MauiApp1.MainPage..ctor()
   at System.Reflection.ConstructorInvoker.InterpretedInvoke(Object obj, IntPtr* args)
   at System.Reflection.ConstructorInvoker.InvokeDirectByRefWithFewArgs(Span`1 copyOfArgs)
   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)
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
   at MauiApp1.iOS.Program.Main(String[] args)

Expected Behavior

AppThemeResourceExtension does not throw an exception.

Steps To Reproduce

Open and run solution from reproduction repository

Link to public reproduction project repository

https://github.com/DooNeGo/MauiApp1

Environment

- .NET MAUI CommunityToolkit: 10.0.0
- OS: Windows 10 Build 19045.5247, iOS Simulator 18.2, Android Emulator Api 34
- .NET MAUI: 9.0.21

Anything else?

No response

@DooNeGo DooNeGo added bug Something isn't working unverified labels Dec 26, 2024
@yurkinh
Copy link

yurkinh commented Jan 2, 2025

The same happens for me. Both platforms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unverified
Projects
None yet
Development

No branches or pull requests

2 participants