7

我有一个 C# 解决方案,它在编译时会吐出一个可执行的二进制文件。二进制文件依赖于一个库,该库是我编写的另一个解决方案的产品,所有相关代码都是我创建的。

最近,我以一种相当随意的方式玩弄了一些项目设置,试图了解 CLR 构建链接的工作原理。不幸的是(可以预见?)我已经设法破坏了我的二进制文件的链接,但我不确定如何解决这个问题。

  • 当我的二进制文件在应用程序崩溃之前得到以下反馈

加载程序集........无法在程序集 MY.Library 中添加类型,版本=1.0.0.0,文化=中性,PublicKeyToken=null - 无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息

  • MY.Library.resources DLL 的融合日志如下。提到的二进制文件不存在,我不知道它在哪里或为什么要加载。

>

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.
  • “资源”DLL 是隐式的吗?还是我一定要引用这个 DLL?我应该如何在图书馆的 SLN 中找到参考资料?

TL;博士

  • 如何删除对不存在资源 DLL 的引用?
4

3 回答 3

3
  • “资源”DLL 是隐式的吗?还是我一定要引用这个 DLL?我应该如何在图书馆的 SLN 中找到参考资料?
  • 如何删除对不存在资源 DLL 的引用?

资源实际上嵌入在您的 dll 中。你不需要引用它。您看到“library.resouce”的原因是因为您的代码要求 .net 通过app.configAppDomain.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#。

于 2011-12-13T00:16:47.843 回答
1

我只是遇到了这样的问题,Visual Studio 2010 找不到各种资源 dll,例如 xaml.resources.dll 和 Presentationcore.resources.dll。结果(最终)这是我将 MainWindow.xaml 移动到子文件夹的结果。我不知道它是否与 Windows 窗体相同,但对于任何在做 WPF 的人:不要移动 MainWindow.xaml。又浪费了我生命中的一天。

于 2011-09-19T12:56:01.647 回答
0

通常你引用的 DLL 应该References在你的 C# 项目的文件夹中(你也应该从那里添加你的外部 DLL)。您可以右键单击要退出的 DLL,然后单击Remove

于 2011-04-22T13:29:13.203 回答