title: Value cannot be null. Parameter name: key (only happens on XAML Designer's design view)
body: <p><strong>XAML Designer</strong> design view shows </p>
  
  <p><strong>An Exception was thrown</strong></p>
  
  <p><strong>ArgumentNullException: Value cannot be null.</strong></p>
  
  <p><strong>Parameter name: key</strong></p>
  
  <p>StackTrace (see after photo)</p>
  
  <p><strong>InnerException: None</strong></p>
  
  <p>I have been struggling for few days on the following issue, which prevents me from using <strong>XAML Designe</strong>r's design view on every affected view.</p>
  
  <p>Yesterday, I eventually managed to isolate this odd behaviour which it particulary hard to trace, since it happens only at design-time, and that seems a conflit between generic type and <strong>DataGrid</strong>'s ItemsSource property (System.Windows.Controls).</p>
  
  <p>So, this is what is shown on the <strong>design view</strong></p>
  
  <p><a href="http://catelproject.com/downloads/catel-4-5-4/" rel="noreferrer"><img src="https://i.stack.imgur.com/qcq7p.png" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>at System.Collections.Generic.Dictionary<code>2.FindEntry(TKey key)    at
    System.Collections.Generic.Dictionary</code>2.TryGetValue(TKey key, TValue&amp;
    value)    at
    System.Windows.Controls.DataGridItemAttachedStorage.TryGetValue(Object
    item, DependencyProperty property, Object&amp; value)    at
    System.Windows.Controls.DataGridRow.RestoreAttachedItemValue(DependencyObject
    objectWithProperty, DependencyProperty property)    at
    System.Windows.Controls.DataGridRow.SyncProperties(Boolean
    forcePrepareCells)    at
    System.Windows.Controls.DataGridRow.PrepareRow(Object item, DataGrid
    owningDataGrid)    at
    System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject
    element, Object item)    at
    System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject
    container, Object item)    at
    System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject
    container)    at
    System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32
    childIndex, UIElement container, Boolean isRecycled)    at
    System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32
    childIndex, UIElement child, Boolean newlyRealized, Boolean
    isBeforeViewport)    at
    System.Windows.Controls.VirtualizingStackPanel.MeasureChild(IItemContainerGenerator&amp;
    generator, IContainItemStorage&amp; itemStorageProvider,
    IContainItemStorage&amp; parentItemStorageProvider, Object&amp; parentItem,
    Boolean&amp; hasUniformOrAverageContainerSizeBeenSet, Double&amp;
    computedUniformOrAverageContainerSize, Double&amp;
    computedUniformOrAverageContainerPixelSize, Boolean&amp;
    computedAreContainersUniformlySized, IList&amp; items, Object&amp; item,
    IList&amp; children, Int32&amp; childIndex, Boolean&amp; visualOrderChanged,
    Boolean&amp; isHorizontal, Size&amp; childConstraint, Rect&amp; viewport,
    VirtualizationCacheLength&amp; cacheSize, VirtualizationCacheLengthUnit&amp;
    cacheUnit, Boolean&amp; foundFirstItemInViewport, Double&amp;
    firstItemInViewportOffset, Size&amp; stackPixelSize, Size&amp;
    stackPixelSizeInViewport, Size&amp; stackPixelSizeInCacheBeforeViewport,
    Size&amp; stackPixelSizeInCacheAfterViewport, Size&amp; stackLogicalSize,
    Size&amp; stackLogicalSizeInViewport, Size&amp;
    stackLogicalSizeInCacheBeforeViewport, Size&amp;
    stackLogicalSizeInCacheAfterViewport, Boolean&amp;
    mustDisableVirtualization, Boolean isBeforeFirstItem, Boolean
    isAfterFirstItem, Boolean isAfterLastItem, Boolean skipActualMeasure,
    Boolean skipGeneration, Boolean&amp;
    hasBringIntoViewContainerBeenMeasured, Boolean&amp;
    hasVirtualizingChildren)    at
    System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size
    constraint, Nullable<code>1&amp; lastPageSafeOffset, List</code>1&amp;
    previouslyMeasuredOffsets, Nullable`1&amp; lastPagePixelSize, Boolean
    remeasure)    at
    System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size
    constraint)    at
    System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size
    constraint)    at System.Windows.FrameworkElement.MeasureCore(Size
    availableSize)    at System.Windows.UIElement.Measure(Size
    availableSize)    at
    System.Windows.ContextLayoutManager.UpdateLayout()    at
    System.Windows.UIElement.UpdateLayout()</p>
  </blockquote>
  
  <p><a href="http://web.sisgarbe.pt/sispub/WebShared/CodeSamples/DataGridBugProof.zip" rel="noreferrer">Sample project source code</a></p>
  
  <p><strong>MyViewModelbase.cs</strong> (this is my generic view model base)</p>
  
  <pre><code>namespace BugProof.ViewModels
  {
      using System.Collections.Generic;
  
      public class MyViewModelBase&lt;TItem&gt; where TItem : class
      {
          public List&lt;TItem&gt; Items { get; set; }
          public MyViewModelBase() { }
      }
  }
  </code></pre>
  
  <p><strong>MyExtendedViewModel.cs</strong> (this my extended view model, which will be based upon a <strong>string</strong> type)</p>
  
  <pre><code>namespace BugProof.ViewModels
  {
      public class MyExtendedViewModel : MyViewModelBase&lt;string&gt;
      {
          public MyExtendedViewModel()
          {
          }
      }
  }
  </code></pre>
  
  <p><strong>MainWindow.xaml</strong></p>
  
  <pre><code>&lt;Window x:Class="BugProof.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:vm="clr-namespace:BugProof.ViewModels"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:BugProof"
          mc:Ignorable="d"
          d:DataContext="{d:DesignInstance {x:Type vm:MyExtendedViewModel}, IsDesignTimeCreatable=False}"                  
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;StackPanel&gt;
          &lt;TextBlock&gt;This is what you should se in the designer&lt;/TextBlock&gt;
          &lt;!--Try replacing following DataGrid by a ListBox or ListView--&gt;
          &lt;DataGrid ItemsSource="{Binding Items}"/&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>MainWindow.xaml.cs</strong> (MainWindow's code behind)</p>
  
  <pre><code>using System.Windows;
  
  namespace BugProof
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
      }
  }
  </code></pre>
  
  <p>Complementary details:</p>
  
  <ul>
  <li>The behaviour does not occur if one replaces <strong>DataGrid</strong> control by a <strong>Listbox</strong>, <strong>ListView</strong> or <strong>ItemsControl</strong></li>
  <li>I am using <strong>Visual Studio 2015, Version 14.0.25431.01 Update 3</strong></li>
  <li>Project is targeted to <strong>.Net Framework 4.5</strong></li>
  </ul>