XamlParseException:无法加载文件或程序集'ResourceLibrary,...'或其某个依赖项。系统找不到指定的文件。

10

发生了System.Windows.Markup.XamlParseException异常。

在PresentationFramework.dll中发生了类型为'System.Windows.Markup.XamlParseException'的一次首要异常。

附加信息:“设置属性'System.Windows.ResourceDictionary.Source'时引发了异常。"行号为'21',行位置为'6'。

"未能加载文件或程序集'ResourceLibrary,Culture=neutral'或其依赖项之一。系统找不到指定的文件。":"ResourceLibrary,Culture=neutral"

=== Pre-bind state information ===
LOG: DisplayName = ResourceLibrary, Culture=neutral
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: ResourceLibrary, Culture=neutral | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\QTAgent32.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/ResourceLibrary/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/ResourceLibrary/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PublicAssemblies/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PublicAssemblies/ResourceLibrary/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/DataCollectors/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/DataCollectors/ResourceLibrary/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/DataCollectors/x86/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/DataCollectors/x86/ResourceLibrary/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/DataCollectors/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/DataCollectors/ResourceLibrary/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/DataCollectors/x86/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/DataCollectors/x86/ResourceLibrary/ResourceLibrary.DLL.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/ResourceLibrary/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/ResourceLibrary/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PublicAssemblies/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PublicAssemblies/ResourceLibrary/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/DataCollectors/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/DataCollectors/ResourceLibrary/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/DataCollectors/x86/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/DataCollectors/x86/ResourceLibrary/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/DataCollectors/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/DataCollectors/ResourceLibrary/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/DataCollectors/x86/ResourceLibrary.EXE.
LOG: Attempting download of new URL file:///C:/Users/me/Documents/projects/Autom/git/Autom/VisCong/VisConf_Tests/bin/Debug/PrivateAssemblies/DataCollectors/x86/ResourceLibrary/ResourceLibrary.EXE.

1
什么是问题? - Sajeetharan
@Sajeetharan,抱歉,我不够快...看看答案... - Tar
2
为什么要踩?stackoverflow.com指出,回答自己的问题不仅是一件好事情,而且明确鼓励这样做。 (http://meta.stackexchange.com/questions/17845/etiquette-for-answering-your-own-question) (http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/) - Tar
3个回答

21

这个问题只是为了提醒我自己以及那些在寻找解决方法时到达此处的人。

参考中的 Copy Local 被设置为 True,但是 DLL 没有被复制到生成文件夹中。

由于我只在 XAML 中使用了这个资源库,所以我不得不添加一个 using 语句:

using ResourceLibrary;

在引用代码中(实际上是调用引用代码的代码,可以是应用程序或单元测试),这使得在目标版本生成目录中创建了 DLL。

Edit:

有时甚至使用 ResourceLibrary 也无法解决问题。解决方案是在 ResourceLibrary 的代码后台创建一些空的静态方法:

namespace ResourceLibrary {
    public static class ReferencePoint {
        public static ReferToMe() {}
    }
}

然后从引用代码中调用它:

ReferencePoint.ReferToMe();

8
为什么要踩(down-voting)?stackoverflow.com声称回答自己的问题不仅是一件好事,而且明确鼓励这样做。参考链接:http://meta.stackexchange.com/questions/17845/etiquette-for-answering-your-own-question,http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/。请注意,翻译内容不能改变原意,也不能包含解释。 - Tar
1
这是一个有效的答案,我曾经遇到过类似的单元测试失败异常。只需将所需的dll添加到测试项目中即可解决问题。Resharper会使测试失败,但NCrunch会通过它。 - Ralph Willgoss

2
这是因为我运行时启动的应用程序引用了一个位于不同位置且版本较旧的DLL。实际使用它的项目有正确的引用,但启动应用程序有错误的引用,因此它正在使用那个旧的DLL。为了解决这个问题,我删除了启动应用程序上的引用,并将其重新添加到正确的位置。

0
我通过将调试平台设置为64位,与参考设置相同,来解决了这个问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接