ResourceDictionary:无法加载文件或程序集或其依赖项之一。该系统找不到指定的文件
ResourceDictionary: Could not load file or assembly or one of its dependencies. The system cannot find the file specified
我有一个引用 WPF class 库 MainLibrary
的应用程序。此 class 库从另一个 WPF class 库 ResourceLibrary
.
中的 ResourceDictionary 获取资源
在设计器和编译时一切正常,来自外部 ResourceDictionary 的资源正确加载,但在运行时应用程序崩溃并出现此异常:
''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.
我在 MainLibrary
的 MainWindow 中添加 ResourceDictionary 是这样的:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/ResourceLibrary;component/ResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
其他观察:
- 如果我将
ResourceDictionary.xaml
直接添加到 MainLibrary
,应用程序将无一例外地运行。另一方面,如果我将另一个 ResourceDictionary 添加到 ResourceLibrary
中,则会引发相同的异常。
- 我尝试重建解决方案,重启 VS 和计算机:)
ResourceDictionary.xaml
的绝对路径解决了问题,但这是不可接受的。
- 将
ResourceLibrary
添加到主要应用引用没有帮助。
ResourceLibrary
正确放入 MainLibrary's
bin 文件夹。
提前谢谢你。
问题的根源很简单。在 Visual Studio 的最新版本中,当我添加对 MainLibrary
的引用时,ResourceLibrary
被引用为嵌套引用。
但我尝试在没有此类选项的 VS2015 中工作。如果我手动将 ResourceLibrary
引用到 主应用程序 ,一切正常。
我有一个引用 WPF class 库 MainLibrary
的应用程序。此 class 库从另一个 WPF class 库 ResourceLibrary
.
在设计器和编译时一切正常,来自外部 ResourceDictionary 的资源正确加载,但在运行时应用程序崩溃并出现此异常:
''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.
我在 MainLibrary
的 MainWindow 中添加 ResourceDictionary 是这样的:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/ResourceLibrary;component/ResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
其他观察:
- 如果我将
ResourceDictionary.xaml
直接添加到MainLibrary
,应用程序将无一例外地运行。另一方面,如果我将另一个 ResourceDictionary 添加到ResourceLibrary
中,则会引发相同的异常。 - 我尝试重建解决方案,重启 VS 和计算机:)
ResourceDictionary.xaml
的绝对路径解决了问题,但这是不可接受的。- 将
ResourceLibrary
添加到主要应用引用没有帮助。 ResourceLibrary
正确放入MainLibrary's
bin 文件夹。
提前谢谢你。
问题的根源很简单。在 Visual Studio 的最新版本中,当我添加对 MainLibrary
的引用时,ResourceLibrary
被引用为嵌套引用。
但我尝试在没有此类选项的 VS2015 中工作。如果我手动将 ResourceLibrary
引用到 主应用程序 ,一切正常。