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

Compiled Bindings: Compilation Error - Object reference not set to an instance of an object #4438

Closed
inforithmics opened this issue Nov 16, 2018 · 5 comments · Fixed by #4483

Comments

@inforithmics
Copy link
Contributor

inforithmics commented Nov 16, 2018

Description

When using Compiled Bindings on a Type with a Generic Base Class and Binding on A Property with the Generic Type: A Compilation Error occurs with Object reference not set to an instance of an object.

Steps to Reproduce

  1. Follwing Base Class
 public class TestViewModel : TestViewModelBase<string>
    {
        public TestViewModel()
        {
            this.Add("test");
            this.SelectedItem = this.First();
        }        
    }

    public class TestViewModelBase<T> : Collection<string>
    {
        public T SelectedItem { get; set; }
    }

Following xaml with Binding to the Generic Property SelectedItem

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:App14"
             x:Class="App14.MainPage"
             x:DataType="local:TestViewModel">

    <StackLayout>
        <!-- Place new controls here -->        
        <Label Text="Number of Items:"/>
        <Label Text="{Binding SelectedItem}" />        
    </StackLayout>

</ContentPage>

Expected Behavior

The Binding Works and the Code compiles

Actual Behavior

The Code doesn't Compile, following error occurs:
Object reference not set to an instance of an object

Basic Information

  • Version with issue: 3.4.0.1008975
  • Last known good version: N/A
  • IDE: Visual Studio 2017 15.9.1
  • Platform Target Frameworks:
    • iOS: 12.1
    • Android: The version of the Android SDK you are compiling against, e.g. 9.0
    • UWP: 16299
  • Android Support Library Version: v27.0.2.1
  • Nuget Packages: N/A
  • Affected Devices: N/A

Screenshots

Reproduction Link

App14.zip

Workaround

Override the Property in the ViewModel than it works.

    public class TestViewModel : TestViewModelBase<string>
    {
        public TestViewModel()
        {
            this.Add("test");
            this.SelectedItem = this.First();
        }

        public override string SelectedItem
        {
            get => base.SelectedItem;
            set => this.SelectedItem = value;
        }
    }

    public class TestViewModelBase<T> : Collection<string>
    {
        public virtual T SelectedItem { get; set; }
    }
@StephaneDelcroix
Copy link
Member

I have to check, but I think this was resolved in #4352, and the fix will be released as part of the 3.4.0 release

@kingces95 kingces95 moved this from New to Ready For Work in Triage Nov 16, 2018
@StephaneDelcroix
Copy link
Member

y, I think that is. reopen if it's not fixed in 3.4.0

Triage automation moved this from Ready For Work to Closed Nov 17, 2018
@inforithmics
Copy link
Contributor Author

inforithmics commented Nov 20, 2018

Can you reopen this issue because it is not a duplicate of #4348.

  1. I used 3.4.0 Version as stated in Version with issue.
  2. This binding works now (was bug in issue)
    <Label Text="{Binding Count}" />
    This binding does not work
    <Label Text="{Binding SelectedItem}" />
    throws Object reference not set to an instance of an object.

The Difference between the two are.

Count is a Property on a Generic Type.
SelectedItem is a Property on Generic Type with a Generic TypeParameter as Type.

So I guess Compiled Bindings tries to find out the Type of this Property and cannot because it is a TypeParameter Type.

Additional Info:

I tried it with the Nightly Nuget package 3.5.1006868 and the issue is still there

Triage automation moved this from Closed to New Nov 20, 2018
StephaneDelcroix added a commit that referenced this issue Nov 20, 2018
@StephaneDelcroix
Copy link
Member

fixed in #4483

@inforithmics
Copy link
Contributor Author

Thanks a lot for the fix.

@samhouts samhouts added this to In Progress in v3.6.0 Nov 20, 2018
Triage automation moved this from New to Closed Nov 21, 2018
@samhouts samhouts moved this from In Progress to Done in v3.6.0 Nov 21, 2018
@samhouts samhouts removed this from Closed in Triage Nov 21, 2018
@samhouts samhouts removed this from Done in v3.6.0 Jan 3, 2019
@samhouts samhouts added this to In Progress in v3.5.0 Jan 11, 2019
@samhouts samhouts moved this from In Progress to Done in v3.5.0 Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
v3.5.0
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants