title: Xamarin Forms build error - StaticResource not found for key
body: <p>I'm just learning XAML and Xamrin.  I'm trying to learn how static styles work.  Here's my XAML code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
               xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
               xmlns:local="clr-namespace:Styles"
               x:Class="Styles.MainPage"&gt;
  
      &lt;ContentPage.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;Style x:key="buttonStyle" TargetType="Button"&gt;
                  &lt;Setter Property="HorizontalOptions" Value="Center"/&gt;
                  &lt;Setter Property="VerticalOptions" Value="Center" /&gt;
                  &lt;Setter Property="TextColor" Value="Red"/&gt;
                  &lt;Setter Property="FontSize" Value="Small"/&gt;
              &lt;/Style&gt;
              &lt;Style TargetType="Label"&gt;
                  &lt;Setter Property="HorizontalOptions" Value="Center"/&gt;
                  &lt;Setter Property="VerticalOptions" Value="Center" /&gt;
                  &lt;Setter Property="TextColor" Value="Blue"/&gt;
                  &lt;Setter Property="FontSize" Value="20"/&gt;
              &lt;/Style&gt;
              &lt;Style x:key="baseStyle" TargetType="View"&gt;
                  &lt;Setter Property="HorizontalOptions" Value="Center"/&gt;
                  &lt;Setter Property="VerticalOptions" Value="Center" /&gt;
              &lt;/Style&gt;
              &lt;Style x:key="entryStyle" TargetType="Entry" BasedOn="{StaticResource baseStyle}"&gt;
                  &lt;Setter Property="TextColor" Value="Green"/&gt;
              &lt;/Style&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/ContentPage.Resources&gt; 
  
      &lt;ContentPage.Content&gt;
          &lt;StackLayout Padding="20"&gt;
              &lt;Label Text="This is label 1 using implicit style"/&gt;
              &lt;Label Text="This is label 2"/&gt;
              &lt;Button 
                  Text="Not using the button style"
                      BorderWidth="2"
                  HorizontalOptions="Center"
                  VerticalOptions="Center"
                      WidthRequest="200"/&gt;
              &lt;Button Style="{StaticResource buttonStyle}" 
                      Text="Using explicit style" 
                      BorderWidth="2"
                      WidthRequest="200"/&gt;
              &lt;Entry Style="{StaticResource entryStyle}" Placeholder="This enty uses an inherited style"/&gt;
  
              &lt;Button Style="{StaticResource buttonStyle}" 
                      Text="Using explicit style" 
                      BorderWidth="2"
                      WidthRequest="200"/&gt;
          &lt;/StackLayout&gt;
      &lt;/ContentPage.Content&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p>Compile works fine, but when running, I get this exception:</p>
  
  <pre><code> [ERROR] FATAL UNHANDLED EXCEPTION: Xamarin.Forms.Xaml.XamlParseException: Position 25:58. StaticResource not found for key baseStyle
  </code></pre>
  
  <p>I don't understand why I get this error since the style 'key' is already defined on the previous line.  Any help is greatly appreciated.</p>