title: Null reference exception on a ListDictionaryInternal when setting bindable property on custom view
body: <p>I have just migrated my Xamarin Forms project to .NET Standard 2.0 and am fighting with some odd behavior. In the following situation, I am getting a Null Reference Exception on a ListDictionaryInternal with no exception breakpoint, no stack trace and no other information available. The situation is, from my view model I am setting the bindable text property on a custom button control. I have debugged all the way through the text setting process and the exception happens after. I am completely stumped by this one. And to be clear, this code was working before the .NET Standard 2.0 migration. Thank you in advance!</p>
  
  <p>UPDATE: </p>
  
  <p>So this exception has started happening with Forms iOS as well but now I am able to get a stack trace when the System.Exception breakpoint hits. Also this is not related to .NET Standard 2.0 because this is also happening when targeting a PCL 4.5 project, Profile 111 to be exact.</p>
  
  <p>I can set a breakpoint in the code behind's OnSizeAllocated override method and see that the view has accepted the bound text and laid out properly. So it is not the binding that is the issue but rather something to do with the laying out of the view. </p>
  
  <p>Also, for clarification, this exception only happens if the text is set with a bindable property. If the text is set in the xaml the exception does not happen.</p>
  
  <p><a href="https://i.stack.imgur.com/UY1fP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UY1fP.png" alt="enter image description here"></a></p>
  
  <p>The ViewModel...</p>
  
  <pre><code>public class SimpleSearchViewModel : BaseViewModel
  {
      enum SearchCatagories
      {
          All,
          SubjectId,
          PublicationNumber
      }
  
      public override void OnStart()
      {
          UpdateTypeButton("ALL");
      }
  
      private void UpdateTypeButton(string item)
      {
          SearchTypeButtonText = item;
      }
  
      private string _searchTypeButtonText;
      public string SearchTypeButtonText
      {
          get
          {
              return _searchTypeButtonText;
          }
          private set
          {
              _searchTypeButtonText = value;
              OnPropertyChanged(nameof(SearchTypeButtonText));
          }
      }
  }
  </code></pre>
  
  <p>The View...</p>
  
  <pre><code>&lt;core:BasePage xmlns="http://xamarin.com/schemas/2014/forms" 
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
  xmlns:viewmodels="using:App.ViewModels"
  xmlns:customcontrols="clr-namespace:App;assembly=App"
  xmlns:core="clr-namespace:App.Core;assembly=App.Core"
  x:Class="Pages.SimpleSearchPage"
  Title="Simple Search"&gt;
  
  &lt;ContentPage.BindingContext&gt;
      &lt;viewmodels:SimpleSearchViewModel /&gt;
  &lt;/ContentPage.BindingContext&gt;
  
  &lt;ContentPage.Content&gt;
  
  &lt;StackLayout Padding=" 10, 10, 10, 10" 
               HorizontalOptions="FillAndExpand" 
               VerticalOptions="FillAndExpand" 
               Orientation="Horizontal" &gt; 
  
              &lt;customcontrols:SVGImageButton x:Name="TypeSelectionButton" 
                              HorizontalOptions="Start" 
                              VerticalOptions="Center"
                              ButtonPressedCommand="{Binding TypeButtonClickedCommand}"
                                 SVGImageName="SVGImages.ic_triangle_down.svg"
                              CommandParameter="{x:Reference TypeSelectionButton}"
                              ButtonText="{Binding SearchTypeButtonText}"
                              ButtonBackgroundColor="{Binding ButtonBackgroundColor}"/&gt;
  
          &lt;/StackLayout&gt;
      &lt;/ContentPage.Content&gt;
  &lt;/core:BasePage&gt;
  </code></pre>
  
  <p>The SVGImageButton...</p>
  
  <pre><code>[XamlCompilation(XamlCompilationOptions.Compile)]
  public class SVGImageButton : ContentView
  {
      private readonly Button _button;
      private readonly SvgCachedImage _svgImage;
  
      public static BindableProperty ButtonTextProperty =    BindableProperty.Create(nameof(ButtonText), typeof(string),   typeof(SVGImageButton), string.Empty, BindingMode.OneWay, propertyChanged: (bindable, oldValue, newValue) =&gt;
      {
          if (newValue == null) return;
          var control = (SVGImageButton)bindable;
          control.ButtonText = newValue.ToString();
      });
  
      public string ButtonText
      {
          get
          {
              return _button.Text;
          }
          set
          {
              _button.Text = value; 
          }
      }
  
      public string SVGImageName { get; set; }
  
      protected override void OnParentSet()
      {
          base.OnParentSet();
  
          _button.Text = ButtonText;
          _svgImage.Source = SvgImageSource.FromResource(SVGImageName);
       }
  
      public SVGImageButton()
      {
          var content = new RelativeLayout();
  
          _button = new Button { BackgroundColor = Color.Gray, TextColor = Color.Black };
          _svgImage = new SvgCachedImage { IsEnabled = false };
  
          content.Children.Add(_button,
                               Constraint.RelativeToParent((parent) =&gt;
                               {
                                   return parent.X;
                               }),
                               Constraint.RelativeToParent((parent) =&gt;
                               {
                                   return parent.Y;
                               }),
                               Constraint.RelativeToParent((parent) =&gt;
                               {
                                   return parent.Width;
                               }),
                               Constraint.RelativeToParent((parent) =&gt;
                               {
                                   return parent.Height;
                               }));
  
          content.Children.Add(_svgImage,
                             Constraint.RelativeToParent((parent) =&gt;
                             {
                                 return parent.Width - (parent.Height / 2) - (parent.Height / 4);
                             }),
                             Constraint.RelativeToParent((parent) =&gt;
                             {
                                 return parent.Height - (parent.Height /     2) - (parent.Height / 4);
                             }),
                             Constraint.RelativeToParent((parent) =&gt;
                             {
                                 return parent.Height / 2;
                             }),
                             Constraint.RelativeToParent((parent) =&gt;
                             {
                                 return parent.Height / 2;
                             }));
  
          Content = content;
          }
      }
  }
  </code></pre>