Repository: CommunityToolkit/Maui

Issue #2003: [BUG] Non-nullable are not valid InvalidOperationException is thrown when using VariableMultiValueConverter
Created: 2024-07-06T21:38:30Z
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
System.InvalidOperationException: 'Non-nullable are not valid'
Expected Behavior
MultiBinding works as it used to in prior versions.
Steps To Reproduce
1- Give MainPage a reference name
x:Name="ThisPage"
2- Copy and paste the following code in MainPage:
    <ContentPage.Resources>
        <toolkit:VariableMultiValueConverter ConditionType="All" x:Key="VariableMultiValueConverterAll" />
        <toolkit:InvertedBoolConverter x:Key="InvertedBoolConverter" />
    </ContentPage.Resources>

    <ScrollView>
        <VerticalStackLayout
            Padding="30,0"
            Spacing="25">
            <VerticalStackLayout.IsEnabled>
                <MultiBinding Converter="{StaticResource VariableMultiValueConverterAll}">
                    <Binding Path="IsEnabled" Source="{x:Reference ThisPage}" Converter="{StaticResource InvertedBoolConverter}" />
                    <Binding Path="IsVisible" Source="{x:Reference ThisPage}" Converter="{StaticResource InvertedBoolConverter}" />
                </MultiBinding>
            </VerticalStackLayout.IsEnabled>
        </VerticalStackLayout>
    </ScrollView>

3- Make sure CommunityToolkit.Maui 9.0.2 is installed
4- Non-nullable are not valid exception is thrown
5- Revert back to CommunityToolkit.Maui 9.0.1 to avoid this issue

Link to public reproduction project repository
https://github.com/usefulBeeing/MauiNonNullableError
Environment
- .NET MAUI CommunityToolkit: 9.0.2
- OS: Windows 10.0.22631 Build 22631
- .NET MAUI: 8.0.61
Anything else?
No response

Duplicate issue #2075: [BUG] IsNullConverter cannont handle nullable with trigger
Created: 2024-07-31T05:22:30Z
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
When using a nullable type, a reference or a value type it throws and System.InvalidOperationException when using the converter with a trigger. It works with the previous version of toolkit, 9.0.1. I have tested on Windows and Android.
Exception details:
System.InvalidOperationException
HResult=0x80131509
Message=Non-nullable are not valid
Source=CommunityToolkit.Maui
StackTrace:
at CommunityToolkit.Maui.Extensions.ValueConverterExtension.g__IsValidNullableValueType|2_2[TTarget](Type targetType)
at CommunityToolkit.Maui.Extensions.ValueConverterExtension.IsValidTargetType[TTarget](Type& targetType, Boolean shouldAllowNullableValueTypes)
at CommunityToolkit.Maui.Extensions.ValueConverterExtension.ValidateTargetType[TTarget](Type targetType, Boolean shouldAllowNullableValueTypes)
at CommunityToolkit.Maui.Converters.BaseConverter2.CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture) at CommunityToolkit.Maui.Converters.ICommunityToolkitValueConverter.Microsoft.Maui.Controls.IValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture) at Microsoft.Maui.Controls.Binding.GetSourceValue(Object value, Type targetPropertyType) at Microsoft.Maui.Controls.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget, SetterSpecificity specificity) at Microsoft.Maui.Controls.BindingExpression.Apply(Object sourceObject, BindableObject target, BindableProperty property, SetterSpecificity specificity) at Microsoft.Maui.Controls.Binding.Apply(Object context, BindableObject bindObj, BindableProperty targetProperty, Boolean fromBindingContextChanged, SetterSpecificity specificity) at Microsoft.Maui.Controls.BindableObject.ApplyBindings(Boolean skipBindingContext, Boolean fromBindingContextChanged) at Microsoft.Maui.Controls.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value) at Microsoft.Maui.Controls.Element.SetChildInheritedBindingContext(Element child, Object context) at Microsoft.Maui.Controls.Element.<OnBindingContextChanged>b__89_0(BindableObject child, Object bc) at Microsoft.Maui.Controls.BindableObjectExtensions.PropagateBindingContext[T](BindableObject self, IEnumerable1 children, Action2 setChildBindingContext) at Microsoft.Maui.Controls.Element.OnBindingContextChanged() at Microsoft.Maui.Controls.VisualElement.OnBindingContextChanged() at Microsoft.Maui.Controls.View.OnBindingContextChanged() at Microsoft.Maui.Controls.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value) at Microsoft.Maui.Controls.Element.SetChildInheritedBindingContext(Element child, Object context) at Microsoft.Maui.Controls.Element.<OnBindingContextChanged>b__89_0(BindableObject child, Object bc) at Microsoft.Maui.Controls.BindableObjectExtensions.PropagateBindingContext[T](BindableObject self, IEnumerable1 children, Action2 setChildBindingContext) at Microsoft.Maui.Controls.Element.OnBindingContextChanged() at Microsoft.Maui.Controls.VisualElement.OnBindingContextChanged() at Microsoft.Maui.Controls.View.OnBindingContextChanged() at Microsoft.Maui.Controls.BindableObject.SetInheritedBindingContext(BindableObject bindable, Object value) at Microsoft.Maui.Controls.Element.SetChildInheritedBindingContext(Element child, Object context) at Microsoft.Maui.Controls.TemplatedPage.SetChildInheritedBindingContext(Element child, Object context) at Microsoft.Maui.Controls.Element.<OnBindingContextChanged>b__89_0(BindableObject child, Object bc) at Microsoft.Maui.Controls.BindableObjectExtensions.PropagateBindingContext[T](BindableObject self, IEnumerable1 children, Action`2 setChildBindingContext)
at Microsoft.Maui.Controls.Element.OnBindingContextChanged()
at Microsoft.Maui.Controls.VisualElement.OnBindingContextChanged()
at Microsoft.Maui.Controls.Page.OnBindingContextChanged()
at Microsoft.Maui.Controls.ContentPage.OnBindingContextChanged()
at Microsoft.Maui.Controls.BindableObject.BindingContextPropertyChanged(BindableObject bindable, Object oldvalue, Object newvalue)
at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent)
at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value)
at Microsoft.Maui.Controls.BindableObject.set_BindingContext(Object value)
at IsNullConverterBug.MainPage..ctor() in C:\Users\danielh\source\repos\IsNullConverterBug\IsNullConverterBug\MainPage.xaml.cs:line 11
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
Expected Behavior
It should not throw an exception and work like in 9.0.1.
Steps To Reproduce

Clone the reproduction repo
Start the app, the app will thow an exception on startup. (In our production app, it resulted in a blank page. I guess the error was handled in the background there. But I got the same exception there too.)

Link to public reproduction project repository
https://github.com/dhindrik/IsNullConverterBug
Environment
- .NET MAUI CommunityToolkit: 9.0.2
- OS: Windows 19045.4529 and Android API 34
- .NET MAUI: Workload: 8.0.61, Nuget: 8.0.70
Anything else?
No response

Closing comment (2024-07-31T13:51:33Z): Possible duplicate: #2003