我有一个 C# 解决方案,它在编译时生成可执行二进制文件。该二进制文件依赖于一个库,该库是我编写的另一个解决方案的产品,所有相关代码都是我创建的。
最近,我以相当随意的方式尝试了一些项目设置,试图了解 CLR 构建链接的工作原理。不幸的是(可以预见?)我已经设法打破了我的二进制文件上的链接,但我不知道如何解决这个问题。
加载组件......无法 在程序集中添加类型 MY.Library,版本=1.0.0.0, 文化=中立,PublicKeyToken=null - 无法加载一个或多个 请求的类型。检索 LoaderExceptions 属性了解更多 信息
>
All probing URLs attempted and failed
*** Assembly Binder Log Entry (22/04/2011 @ 10:34:17) ***
The operation failed. Bind result: hr
= 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll Running under executable G:\SVN\dev\Debug\MYExecutable.exe
--- A detailed error log follows.
=== Pre-bind state information === LOG: User = UBERIT\gavina LOG: DisplayName = MY.Library.resources, Version=1.0.0.0, Culture=en, PublicKeyToken=null (Fully-specified) LOG: Appbase = file:///G:/SVN/dev/Debug LOG: Initial PrivatePath = x64 LOG: Dynamic Base = NULL LOG: Cache Base = NULL LOG: AppName = MYExecutable.exe Calling assembly : MY.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
=== LOG: This bind starts in default load context.
LOG: Using application configuration file: G:\BuildSVN\apps\ExecSys\MYExecutable\dev\Debug\MYExecutable.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\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:///G:/SVN/dev/Debug/en/MY.Library.resources.DLL.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/en/MY.Library.resources/MY.Library.resources.DLL.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/x64/en/MY.Library.resources.DLL.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/x64/en/MY.Library.resources/MY.Library.resources.DLL.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/en/MY.Library.resources.EXE. LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/en/MY.Library.resources/MY.Library.resources.EXE.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/x64/en/MY.Library.resources.EXE.
LOG: Attempting download of new URL file:///G:/SVN/dev/Debug/x64/en/MY.Library.resources/MY.Library.resources.EXE.
LOG: All probing URLs attempted and failed.
TL;博士
- “资源”DLL 是隐式的吗?或者我一定要参考一下 这个DLL?我应该如何在 SLN 中找到该库的参考文献?
- 如何删除对不存在的资源 DLL 的引用?
资源实际上嵌入在您的 dll 中。您无需引用它。
您看到“library.resouce”的原因是您的代码要求 .net 通过 app.config 或 AppDomain.AssemblyResolve 事件手动加载程序集。
就你的情况而言,我认为是后者。只需找到该事件处理程序并执行如下操作:
static System::Reflection::Assembly^ HandleAssemblyResolveEvent(System::Object^ sender, System::ResolveEventArgs^ args)
{
System::String^ assemblyName = args->Name->Substring(0, args->Name->IndexOf(","));
if(assemblyName->EndsWith(".resources")) return nullptr;
}
代码是 C++\CLI 语言,但很容易翻译成 C#。
我刚刚遇到了这样的问题,Visual Studio 2010找不到各种资源DLL,例如xaml.resources.dll和presentationcore.resources.dll。事实证明(最终)这是我将 MainWindow.xaml 移动到子文件夹的结果。我不知道它是否与 Windows 窗体相同,但对于任何使用 WPF 的人来说:请勿移动 MainWindow.xaml。我生命中又浪费了一天。
通常,您引用的 DLL 应该位于 C# 项目的
References
文件夹中(您还应该从那里添加外部 DLL)。您可以右键单击要踢出的 DLL,然后单击 Remove
。
对我来说它可以修复 Visual Studio