title: WPF/XAML How to specify the assembly to load the resource from?
body: <p>I'm working on a WPF class library, not an application. Here is an example of a Label I'm making in c# and I'd like to "style" it using XAML.</p>
  
  <pre><code>   private void CreateElement(int i)
      {
          UIElementOut[i] = new Label();
          var uiElement = (Label)UIElementOut[i];
          uiElement.HorizontalAlignment = HorizontalAlignment.Center;
          uiElement.VerticalAlignment = VerticalAlignment.Center;
          uiElement.FontFamily = new FontFamily(FFontInput[i]);
          uiElement.FontSize = Convert.ToDouble(FontSizeIn[i]);
          uiElement.Content = TextIn[i];
          Brush BgBrushColor = new SolidColorBrush(RGBAToMediaColor(FBgCol[i]));
          Brush FgBrushColor = new SolidColorBrush(RGBAToMediaColor(FFgCol[i]));
          uiElement.Background = BgBrushColor;
          uiElement.Foreground = FgBrushColor;
          Uri uri = new Uri("Styles/LabelStyle.xaml", UriKind.Relative);
          StreamResourceInfo info = Application.GetContentStream(uri);
          System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader();
          ResourceDictionary myResourceDictionary = (ResourceDictionary)reader.LoadAsync(info.Stream);
          Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
          Style myLabelStyle = myResourceDictionary["LabelStyle"] as Style;
          uiElement.Style = myLabelStyle;
      }
  </code></pre>
  
  <p>For this I have ressourcedictionnary containing my LabelStyle, everything is compiling without problem.</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:WpfApplication1"&gt;
  &lt;Style x:Key="LabelStyle" TargetType="{x:Type Label}"&gt;
      &lt;Setter Property="Height" Value="53" /&gt;
      &lt;Setter Property="Width" Value="130" /&gt;
      &lt;Setter Property="HorizontalAlignment" Value="Left" /&gt;
      &lt;Setter Property="Margin" Value="99,71,0,0" /&gt;
      &lt;Setter Property="VerticalAlignment" Value= "Top" /&gt;
      &lt;Setter Property="Foreground" Value="#FFE75959" /&gt;
      &lt;Setter Property="FontFamily" Value="Calibri" /&gt;
      &lt;Setter Property="FontSize" Value="40" /&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p></p>
  
  <p>but when I use my dll later on, the style is not applied and I have this error message :</p>
  
  <pre><code>ERR : Assembly.GetEntryAssembly() returns null. Set the Application.ResourceAssembly property or use the pack://application:,,,/assemblyname;component/ syntax to specify the assembly to load the resource from.
  </code></pre>
  
  <p>here is my actual App.xaml with build action setup to page :</p>
  
  <pre><code>&lt;Application x:Class="WpfApplication1.App"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:local="clr-namespace:WpfApplication1"
           StartupUri="MainWindow.xaml"&gt;
  &lt;Application.Resources&gt;
  
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p></p>
  
  <p>How to specify the assembly to load the resource from ?
  I'm fairly new to WPF and I'm stuck on this problem, thanks in advance.</p>
  
  <p>EDIT 1 : </p>
  
  <p>I tried as my Assembly Name is WpfApplication1 (see here <a href="http://postimg.org/image/ksyj9xi5p/" rel="nofollow">http://postimg.org/image/ksyj9xi5p/</a>)</p>
  
  <pre><code>ResourceDictionary myResourceDictionary = Application.LoadComponent(new Uri("/WpfApplication1;component/Styles/LabelStyle.xaml", UriKind.RelativeOrAbsolute)) as ResourceDictionary;
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>ResourceDictionary myResourceDictionary = (ResourceDictionary)reader.LoadAsync(info.Stream);
  </code></pre>
  
  <p>and get the same error.</p>