I just migrated the Xamarin Forms project to .NET Standard 2.0 and am struggling with some weird behavior. In the following situation, I get a Null Reference Exception in the ListDictionaryInternal with no exception breakpoints, stack traces, and no other information available. The situation is that from the model of my view, I set the bindable text property on the user button control. I completely debugged the text tuning process, and the exception occurs after. I am completely shocked by this. And to be clear, this code worked before the migration of .NET Standard 2.0. Thank you in advance!
UPDATE:
So, this exception has already started with Forms iOS, but now I can get the stack trace when the System.Exception breakpoint is removed. It is also not related to .NET Standard 2.0, because it also happens when targeting a PCL 4.5 project, namely profile 111.
I can set a breakpoint in the code of the OnSizeAllocated override method and see that the view has accepted the associated text and is laid out correctly. Thus, this is not a problem, but a problem with highlighting a view.
In addition, for clarification, this exception occurs only if the text is set using the bindable property. If the text is set to xaml, an exception does not occur.

ViewModel ...
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)); } } }
View...
<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"> <ContentPage.BindingContext> <viewmodels:SimpleSearchViewModel /> </ContentPage.BindingContext> <ContentPage.Content> <StackLayout Padding=" 10, 10, 10, 10" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Orientation="Horizontal" > <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}"/> </StackLayout> </ContentPage.Content> </core:BasePage>
SVGImageButton ...
[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) => { 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) => { return parent.X; }), Constraint.RelativeToParent((parent) => { return parent.Y; }), Constraint.RelativeToParent((parent) => { return parent.Width; }), Constraint.RelativeToParent((parent) => { return parent.Height; })); content.Children.Add(_svgImage, Constraint.RelativeToParent((parent) => { return parent.Width - (parent.Height / 2) - (parent.Height / 4); }), Constraint.RelativeToParent((parent) => { return parent.Height - (parent.Height / 2) - (parent.Height / 4); }), Constraint.RelativeToParent((parent) => { return parent.Height / 2; }), Constraint.RelativeToParent((parent) => { return parent.Height / 2; })); Content = content; } } }