title: Trouble referencing a Resource Dictionary that contains a Merged Dictionary
body: <p>I have a library, CommonLibraryWpfThemes, with several Resource Dictionary XAML files in it. My Themes/Generic.xml file contains a ResourceDictionary.MergedDictionaries declaration that merges all the other files together.</p>
  
  <p><strong>Generic.xaml</strong></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;ResourceDictionary.MergedDictionaries&gt;
          &lt;ResourceDictionary
              Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/BrushDictionary.xaml" /&gt;
          &lt;ResourceDictionary
              Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/TextBlockDictionary.xaml" /&gt;
          &lt;ResourceDictionary
              Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/LabelDictionary.xaml" /&gt;
          &lt;ResourceDictionary
              Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/ButtonDictionary.xaml" /&gt;
          &lt;ResourceDictionary
              Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml" /&gt;
      &lt;/ResourceDictionary.MergedDictionaries&gt;
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>In my application project, I have a reference to CommonLibraryWpfThemes, and I explicitly reference Generic.xml in my App.xaml file.</p>
  
  <p><strong>App.xaml -- FAILS</strong></p>
  
  <pre><code>&lt;Application
      x:Class="MyApp.App"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
      &lt;Application.Resources&gt;
          &lt;ResourceDictionary
              Source="/CommonLibraryWpfThemes;component/Themes/Generic.xaml" /&gt;
      &lt;/Application.Resources&gt;
  &lt;/Application&gt;
  </code></pre>
  
  <p>This doesn't work. I get the following error when I run my app:</p>
  
  <pre><code>System.Windows.Markup.XamlParseException occurred
    Message="Cannot find resource named '{_fadedOrangeBrush}'. Resource names are case sensitive.  Error at object 'System.Windows.Setter' in markup file 'CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml' Line 18 Position 13."
    Source="PresentationFramework"
    LineNumber=18
    LinePosition=13
  </code></pre>
  
  <p>If I place the contents of Generic.xaml into App.xaml directly, everything works fine:</p>
  
  <p><strong>App.xaml -- SUCCEEDS</strong></p>
  
  <pre><code>&lt;Application
      x:Class="MyApp.App"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
      &lt;Application.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;ResourceDictionary.MergedDictionaries&gt;
                  &lt;ResourceDictionary
                      Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/BrushDictionary.xaml" /&gt;
                  &lt;ResourceDictionary
                      Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/TextBlockDictionary.xaml" /&gt;
                  &lt;ResourceDictionary
                      Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/LabelDictionary.xaml" /&gt;
                  &lt;ResourceDictionary
                      Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/ButtonDictionary.xaml" /&gt;
                  &lt;ResourceDictionary
                      Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml" /&gt;
              &lt;/ResourceDictionary.MergedDictionaries&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/Application.Resources&gt;
  &lt;/Application&gt;
  </code></pre>
  
  <hr>
  
  <p>Maybe I'm going about this in the wrong way. My goal is to make it easy to reference all my theme resources from multiple applications without having to list out all the individual files. Is there a recommended way to do this? (Note: I'm not trying to switch between multiple themes--I just have one theme.)</p>
  
  <p>As a bonus, it would be nice if someone could tell me how to reference resources in an external library without breaking the designer in Visual Studio.</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I tried wrapping the ResourceDictionary in a ResourceDictionary.MergedDictionary element, but that also didn't work (I get the same error):</p>
  
  <pre><code>&lt;Application
      x:Class="MyApp.App"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
      &lt;Application.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;ResourceDictionary.MergedDictionaries&gt;
                  &lt;ResourceDictionary
                      Source="/CommonLibraryWpfThemes;component/Themes/Generic.xaml" /&gt;
              &lt;/ResourceDictionary.MergedDictionaries&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/Application.Resources&gt;
  &lt;/Application&gt;
  </code></pre>