Home > front end >  ResourceDictionary: Could not load file or assembly or one of its dependencies. The system cannot fi
ResourceDictionary: Could not load file or assembly or one of its dependencies. The system cannot fi

Time:04-16

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:

  1. If I add ResourceDictionary.xaml directly into the MainLibrary, app works with no exceptions. On the other hand, if I add another ResourceDictionary into the ResourceLibrary, the same exception is thrown.
  2. I've tried to rebuild solution, restart VS and computer :)
  3. Absolute path to ResourceDictionary.xaml solves the problem, but it's not acceptable.
  4. Adding ResourceLibrary to main app references doesn't help.
  5. ResourceLibrary is put properly into the MainLibrary'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.

  • Related