Repository navigation
Closed
Labels
area/essentialsIssue/Discussion/PR that has to do with EssentialsIssue/Discussion/PR that has to do with Essentialsarea/extensionsIssue/Discussion/PR that has to do with ExtensionsIssue/Discussion/PR that has to do with ExtensionsbugSomething isn't workingSomething isn't working
Description
Is there an existing issue for this?
- I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
AppThemeResourceExtension crashes the app 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.21Anything else?
No response
Reacted by Edward Brey, Prateek Mahendrakar, Koen Zwikstra, Reinier, R. Abächerli, Tino Schubert and Nico
Metadata
Metadata
Assignees
Labels
area/essentialsIssue/Discussion/PR that has to do with EssentialsIssue/Discussion/PR that has to do with Essentialsarea/extensionsIssue/Discussion/PR that has to do with ExtensionsIssue/Discussion/PR that has to do with ExtensionsbugSomething isn't workingSomething isn't working
Activity
yurkinh commentedon Jan 2, 2025
The same happens for me. Both platforms
malsabi commentedon Jan 12, 2025
I'm also having this issue on Windows & Android. Reverting back to 9.1.1 resolves the issue.
baaaaif commentedon Jan 14, 2025
+1
same here
zwikk commentedon Jan 17, 2025
Same. Not fixed in 11.0.0 😫
pmahend1 commentedon Jan 17, 2025
This issue has not been triaged yet. Someone needs to do it and create PR.
baaaaif commentedon Jan 20, 2025
Maybe you need to adjust the title and mention that the app crashes and that it's not just an exception that could be caught.
I'm a bit surprised that this doesn't get any attention from the maintainers. Sorry @jfversluis - I'll just tag you as a managing maintainer.
[-][BUG] AppThemeResourceExtension throws exception in Release after updating community toolkit version to 10.0.0[/-][+][BUG] AppThemeResourceExtension crashes the app after updating the community toolkit version to 10.0.0[/+]jfversluis commentedon Jan 20, 2025
@pmahend1 or anyone here, feel free to do so 😉 Its a community project, we're all in this together!
Quick investigation shows its because this path is invoked:
https://github.com/CommunityToolkit/Maui/blob/main/src/CommunityToolkit.Maui/Extensions/AppThemeResourceExtension.shared.cs#L27-L30
More specifically:
serviceProvider.GetService(typeof(IProvideValueTarget))is null so that's why it breaks. Now what is the fix, that is the question.jfversluis commentedon Jan 20, 2025
Oh found it, it wasn't actually that hard.
Could you try the resulting build from #2460 to verify that fixes it for you?
baaaaif commentedon Jan 20, 2025
I can confirm that it fixes the problem for me on Android
big thx Gerald
DooNeGo commentedon Jan 20, 2025
I can also confirm the fix, it works for me on Android and Windows.
thx Gerald
pmahend1 commentedon Jan 20, 2025
@jfversluis Thanks for the fix. I was trying to find a fix but was not able to. I did not know about
typeof(IProvideParentValues)😄