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 crash in Release mode: Value does not fall within the expected range. (Parameter 'serviceProvider') #2431

Closed
2 tasks done
pmahend1 opened this issue Jan 8, 2025 · 1 comment
Labels
bug Something isn't working unverified

Comments

@pmahend1
Copy link

pmahend1 commented Jan 8, 2025

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

With version 10.0.0 CommunityToolkit there is some change for AppThemeResourceExtension that causes only release build to crash. Debug builds run fine.

Error

Exception has occurred: System.ArgumentException
Value does not fall within the expected range. (Parameter 'serviceProvider')
    at CommunityToolkit.Maui.Extensions.AppThemeResourceExtension.ProvideValue(IServiceProvider serviceProvider)
    at MauiAppXyz.MainPage.InitializeComponent()
    at MauiAppXyz.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()
    at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.__Registrar_Callbacks__.callback_131_Microsoft_Maui_Controls_Platform_Compatibility_ShellSectionRootRenderer_ViewDidLoad(IntPtr pobj, IntPtr sel, IntPtr* exception_gchandle)

Here is the reproducible sample

pmahend1/maui-toolkit-appresource-issue

It is most likely due to recent change [ContentProperty(nameof(Key)), RequireService([typeof(IServiceProvider)])] in AppThemeResourceExtension. I have tried registering IServiceProvider with default ServiceProvider and tried registering and resolving AppShell as mentioned in dependency-injection/limitations-with-xaml-resources

Work-around

Reverted nuget to 9.1.1

Expected Behavior

AppThemeResourceExtension should run fine in both debug and release configurations.

Steps To Reproduce

  1. Clone pmahend1/maui-toolkit-appresource-issue main branch.
  2. Run it on Debug mode on either iOS or Android
  3. Run it on Release mode on either iOS or Android

Link to public reproduction project repository

https://github.com/pmahend1/maui-toolkit-appresource-issue

Environment

- .NET MAUI CommunityToolkit: 10.0.0
- OS: NA but on macOS Sequoia 15.2
- .NET MAUI: Dotnet 9.0.101 , MAUI workload : 9.0.100-manifests.1e472b70

Anything else?

Reverting to v9.1.1 throws tens of warnings for XAML compiled binding and not having required-service everywhere

@pmahend1 pmahend1 added bug Something isn't working unverified labels Jan 8, 2025
@pmahend1
Copy link
Author

pmahend1 commented Jan 8, 2025

Found that it is duplicate of #2415

@pmahend1 pmahend1 closed this as completed Jan 8, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working unverified
Projects
None yet
Development

No branches or pull requests

1 participant