I have application which refers to WPF class library MainLibrary
. This class library gets resources from ResourceDictionary in another WPF class library ResourceLibrary
.
In designer and at compile time everything works fine, resources from external ResourceDictionary load correctly, but at runtime app crashes with this exception:
''Set property 'System.Windows.ResourceDictionary.Source' threw an exception.'
FileNotFoundException: Could not load file or assembly 'ResourceLibrary, Culture=neutral' or one of its dependencies. The system cannot find the file specified.
I add ResourceDictionary in MainWindow of MainLibrary
that way:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/ResourceLibrary;component/ResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
Other observations:
- If I add
ResourceDictionary.xaml
directly into theMainLibrary
, app works with no exceptions. On the other hand, if I add another ResourceDictionary into theResourceLibrary
, the same exception is thrown. - I've tried to rebuild solution, restart VS and computer :)
- Absolute path to
ResourceDictionary.xaml
solves the problem, but it's not acceptable. - Adding
ResourceLibrary
to main app references doesn't help. ResourceLibrary
is put properly into theMainLibrary's
bin folder.
Thank you in advance.
CodePudding user response:
The root of the problem was very simple. In the latest versions of Visual Studio, when I add reference to MainLibrary
, ResourceLibrary
becomes referenced as nested reference.
But I tried to work in VS2015, where there is no such option. If I manually reference ResourceLibrary
to main app, everything works fine.