title: Why "the resource could not be resolved" using ComponentResourceKey?
body: <p>I'm trying to reuse custom resources using <code>ComponentResourceKey</code>, but it doesn't work, and I get this warning:</p>
  
  <p><code>Warning    12  The resource "{ComponentResourceKey ResourceId=SadTileBrush, TypeInTargetAssembly={x:Type res:CustomResources}}" could not be resolved.</code></p>
  
  <p>Here is the <code>ResourceLibrary/Themes/generic.xaml</code>:</p>
  
  <pre><code>&lt;ResourceDictionary
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:ResourceLibrary"&gt;
      &lt;ImageBrush x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:CustomResources},
                          ResourceId=MyBrush}"
          ImageSource="ResourceLibrary;component/../../myImage.jpg"&gt;
      &lt;/ImageBrush&gt;
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>And the <code>ResourceLibrary/CustomResources.cs</code>:</p>
  
  <pre><code>namespace ResourceLibrary{
      public class CustomResources{}
  }
  </code></pre>
  
  <p>The usage is as follows (in <code>SomeOtherProject/MyWindow.xaml</code>):</p>
  
  <pre><code>&lt;Button Background="{DynamicResource {ComponentResourceKey
                      TypeInTargetAssembly={x:Type res:CustomResources}, 
                      ResourceId=MyBrush}}"&gt; Some text &lt;/Button&gt;
  </code></pre>
  
  <p>Why "the resource could not be resolved" ?</p>
  
  <p>Please note that I'm aware of the SO question "<a href="https://stackoverflow.com/questions/1422538/getting-a-componentresourcekey-to-work">Getting a ComponentResourceKey to Work?</a>", but the problem in that case was in a code-behind, which I lack anyway...</p>