Hello!
We have recently updated our MAUI app from Telerik 13.2 to the latest 14 version. After the update, our Android app would crash on startup.
Our logs suggested the issue came from the RadSpinnerResourceDictionary class, specifically the setting the TextColorProperty now calls resourceExtension.ProvideValue() method which expects the value of the key added in the constructor:
public RadSpinnerResourceDictionary()
{
this.Add("SpinnerSelectedTextColor", (object) Application.AccentColor);
this.InitializeComponent();
}We do not set this value, and the value is nullable.
In our Styles.xml we have a custom style for the RadListPicker. The app crashes if we leave that set, and does not if we comment out the style. However, the app experiences a weird behavior afterwards, where native controls (buttons, pickers) do not render correctly or at all.
Here is the log we have:
System.NullReferenceException: Object reference not set to an instance of an object.
at object StaticResourceExtension.CastTo(object value, object targetProperty)() in StaticResourceExtension.cs:line 62
at object StaticResourceExtension.ProvideValue(IServiceProvider serviceProvider)() in StaticResourceExtension.cs:line 53
at void RadSpinnerResourceDictionary.InitializeComponent()()
at new RadSpinnerResourceDictionary()()
at static RadSpinner()()
System.TypeInitializationException: The type initializer for 'Telerik.Maui.Controls.RadSpinner' threw an exception.
at void RadPickersResources.InitializeComponent()()
at new RadPickersResources()()
at RadPickersResources RadPickersResources.get_Resources()()
at object RadPickersResources.GetResource(string resourceKey)()
at Style RadPickersResources.get_PickerContentViewHeaderLabelStyle()()
at static PickerPopupSettings()()
System.TypeInitializationException: The type initializer for 'Telerik.Maui.Controls.PickerPopupSettings' threw an exception.
at object MethodBaseInvoker.InterpretedInvoke_Constructor(object obj, IntPtr* args)() in MethodBaseInvoker.Mono.cs:line 32
at object MethodBaseInvoker.InvokeWithNoArgs(object obj, BindingFlags invokeAttr)() in MethodBaseInvoker.cs:line 57
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
at object MethodBaseInvoker.InvokeWithNoArgs(object obj, BindingFlags invokeAttr)() in MethodBaseInvoker.cs:line 61
at object RuntimeType.CreateInstanceMono(bool nonPublic, bool wrapExceptions)() in RuntimeType.Mono.cs:line 1825
at object RuntimeType.CreateInstanceDefaultCtor(bool publicOnly, bool wrapExceptions)() in RuntimeType.Mono.cs:line 1627
at object Activator.CreateInstance(Type type, bool nonPublic, bool wrapExceptions) x 3() in Activator.RuntimeType.cs:line 97
at void CreateValuesVisitor.Visit(ElementNode node, INode parentNode)() in CreateValuesVisitor.cs:line 113
at void ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)() in XamlNode.cs:line 142
at void ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode) x 2() in XamlNode.cs:line 138
at void RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)() in XamlNode.cs:line 194
at void XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, bool useDesignProperties)() in XamlLoader.cs:line 233
at void XamlLoader.Load(object view, string xaml, Assembly rootAssembly, bool useDesignProperties)() in XamlLoader.cs:line 103
at void XamlLoader.Load(object view, string xaml, bool useDesignProperties)() in XamlLoader.cs:line 57
at void XamlLoader.Load(object view, Type callingType)() in XamlLoader.cs:line 53
at __TypeAC55B29C835AE2FB Extensions.LoadFromXaml<__TypeAC55B29C835AE2FB>(__TypeAC55B29C835AE2FB view, Type callingType)() in ViewExtensions.cs:line 52
at void __TypeAC55B29C835AE2FB.InitializeComponent()() in obj/Debug/net10.0-android/android-arm64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.XamlGenerator/Resources_Styles_Styles.xaml.sg.cs:line 24
at new __TypeAC55B29C835AE2FB()() in obj/Debug/net10.0-android/android-arm64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.XamlGenerator/Resources_Styles_Styles.xaml.sg.cs:line 18
at object MethodBaseInvoker.InterpretedInvoke_Constructor(object obj, IntPtr* args)() in MethodBaseInvoker.Mono.cs:line 32
at object MethodBaseInvoker.InvokeWithNoArgs(object obj, BindingFlags invokeAttr)() in MethodBaseInvoker.cs:line 57
at ResourceDictionary ResourceDictionary.GetOrCreateInstance(Type type)+(Type _) => { }() in ResourceDictionary.cs:line 95
at ResourceDictionary ConditionalWeakTable<Type, ResourceDictionary>.GetValue(Type key, CreateValueCallback createValueCallback)() in ConditionalWeakTable.cs:line 314
at ResourceDictionary ResourceDictionary.GetOrCreateInstance(Type type)() in ResourceDictionary.cs:line 87
at void ResourceDictionaryHelpers.SetAndLoadSource(ResourceDictionary rd, Uri value, string resourcePath, Assembly assembly, IXmlLineInfo lineInfo)() in ResourceDictionaryHelpers.cs:line 42
at void ResourceDictionaryHelpers.LoadFromSource(ResourceDictionary rd, string value, Type rootType, IXmlLineInfo lineInfo)() in ResourceDictionaryHelpers.cs:line 35
at void ApplyPropertiesVisitor.SetPropertyValue(object xamlelement, XmlName propertyName, object value, object rootElement, INode node, HydrationContext context, IXmlLineInfo lineInfo)() in ApplyPropertiesVisitor.cs:line 372
at void ApplyPropertiesVisitor.Visit(ValueNode node, INode parentNode)() in ApplyPropertiesVisitor.cs:line 70
at void ValueNode.Accept(IXamlNodeVisitor visitor, INode parentNode)() in XamlNode.cs:line 61
at void ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)() in XamlNode.cs:line 136
at void FillResourceDictionariesVisitor.Visit(ElementNode node, INode parentNode)() in FillResourceDictionariesVisitor.cs:line 66
at void ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)() in XamlNode.cs:line 131
at void ListNode.Accept(IXamlNodeVisitor visitor, INode parentNode)() in XamlNode.cs:line 212
at void ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)() in XamlNode.cs:line 136
at void RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)() in XamlNode.cs:line 192
at void XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, bool useDesignProperties)() in XamlLoader.cs:line 236
at void XamlLoader.Load(object view, string xaml, Assembly rootAssembly, bool useDesignProperties)() in XamlLoader.cs:line 103
at void XamlLoader.Load(object view, string xaml, bool useDesignProperties)() in XamlLoader.cs:line 57
at void XamlLoader.Load(object view, Type callingType)() in XamlLoader.cs:line 53
at App Extensions.LoadFromXaml<App>(App view, Type callingType)() in ViewExtensions.cs:line 52
at void App.InitializeComponent()() in obj/Debug/net10.0-android/android-arm64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.XamlGenerator/App.xaml.sg.cs:line 20
at new App()() in App.xaml.cs:line 247
at object MethodBaseInvoker.InterpretedInvoke_Constructor(object obj, IntPtr* args)() in MethodBaseInvoker.Mono.cs:line 32
at object MethodBaseInvoker.InvokeWithNoArgs(object obj, BindingFlags invokeAttr)() in MethodBaseInvoker.cs:line 57
at object RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)() in RuntimeConstructorInfo.cs:line 155
at object CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)() in CallSiteRuntimeResolver.cs:line 69
at object CallSiteVisitor<RuntimeResolverContext, object>.VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)() in CallSiteVisitor.cs:line 48
at object CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)() in CallSiteRuntimeResolver.cs:line 92
at object CallSiteVisitor<RuntimeResolverContext, object>.VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)() in CallSiteVisitor.cs:line 27
at object CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)() in CallSiteRuntimeResolver.cs:line 30
at ServiceAccessor ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)() in ServiceProvider.cs:line 251
at ServiceAccessor ConcurrentDictionary<ServiceIdentifier, ServiceAccessor>.GetOrAdd(ServiceIdentifier key, Func<ServiceIdentifier, ServiceAccessor> valueFactory)() in ConcurrentDictionary.cs:line 1201
at object ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope) x 2() in ServiceProvider.cs:line 211
at object WrappedServiceProvider.GetService(Type serviceType) x 2() in MauiContext.cs:line 87
at IApplication ServiceProviderServiceExtensions.GetService<IApplication>(IServiceProvider provider)() in ServiceProviderServiceExtensions.cs:line 25
at void SentryMauiAppBuilderExtensions.HandleMauiEvents(IPlatformApplication platformApplication, bool bind)() in SentryMauiAppBuilderExtensions.cs:line 158
at void <>c.<RegisterMauiEventsBinder>b__3_2(?)+(Application application) => { }() in SentryMauiAppBuilderExtensions.cs:line 134
at void MauiApplication.OnCreate()+(OnApplicationCreating del) => { }() in MauiApplication.cs:line 44
at void LifecycleEventServiceExtensions.InvokeLifecycleEvents<OnApplicationCreating>(IServiceProvider services, Action<OnApplicationCreating> action)() in LifecycleEventServiceExtensions.cs:line 31
at void MauiApplication.OnCreate()() in MauiApplication.cs:line 44
at void Application.n_OnCreate(IntPtr jnienv, IntPtr native__this)()Setting the Application.AccentColor in App.xaml.cs before InitializeComponent(); seems to fix the issue.
If the previous behavior is expected to change, this should be marked as a breaking change.
