title: Out of bound error in resource dictionary
body: <p>I have put my shared styles in a single resource dictionary which I include in the application. For example, in a file called <code>GlobalStyles.xaml</code> I have the following:</p>
  
  <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
      &lt;Style x:Key="BaseStyle" TargetType="FrameworkElement"&gt;...&lt;/Style&gt;
      &lt;Style x:Key="ExtendedStyle" TargetType="FrameworkElement" BasedOn="{StaticResource BaseStyle}"&gt;...&lt;/Style&gt;
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>I include this file in the app.xaml as follows:</p>
  
  <pre><code>&lt;Application.Resources&gt;
      &lt;ResourceDictionary Source="GlobalStyles.xaml" /&gt;
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p>This should work but I am getting the following build error for the ExtendedStyle: <code>Error: Index was outside the bounds of the array.</code>. If I remove the <code>BasedOn</code> directive I get the same error for <code>BaseStyle</code> but none for <code>ExtendedStyle</code>. This is really wierd. Can anybody explain this error?</p>
  
  <p><strong>EDIT:</strong>
  The styles are:</p>
  
  <pre><code>    &lt;Style x:Key="BaseStyle" TargetType="FrameworkElement"&gt;
      &lt;!-- Background --&gt;
      &lt;Setter Property="Control.Background" Value="{StaticResource White0ColorBrush}"/&gt;
      &lt;!-- Border --&gt;
      &lt;Setter Property="Control.BorderBrush" Value="{StaticResource Green1ColorBrush}"/&gt;
      &lt;Setter Property="Control.BorderThickness" Value="0"/&gt;
      &lt;!-- Font --&gt;
      &lt;Setter Property="Control.FontWeight" Value="Light"/&gt;
      &lt;Setter Property="Control.Foreground" Value="{StaticResource Green0ColorBrush}"/&gt;
      &lt;/Style&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>&lt;Style x:Key="ExtendedStyle" TargetType="FrameworkElement" BasedOn="{StaticResource BaseStyle}"&gt;
      &lt;Setter Property="Control.Background" Value="{StaticResource Green1ColorBrush}"/&gt;
      &lt;Setter Property="Control.Foreground" Value="{StaticResource White0ColorBrush}"/&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>I don't think there is anything special about these two styles. On restarting VS, I am getting the error for another style dependent on <code>ExtendedStyle</code>.</p>
  
  <p><strong>EDIT 2:</strong>
  I created a new empty WPF Application project and included the <code>GlobalStyles.xaml</code> file in the app.xml. That built fine. Then I added just these lines to the window.xaml and got the same error:</p>
  
  <pre><code>    &lt;Grid&gt;
        &lt;Border BorderThickness="2" CornerRadius="5" BorderBrush="{StaticResource White0ColorBrush}" Style="{StaticResource ExtendedBaseStyle}"&gt;
          &lt;Grid&gt;
             &lt;TextBox x:Name="SearchField" Height="20" BorderThickness="0" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" /&gt;
          &lt;/Grid&gt;
        &lt;/Border&gt;
      &lt;/Grid&gt;
  </code></pre>