C# - 'Resources' DLL加载失败,因为其不存在 - 我该如何找到引用以便删除它?

7
我有一个C#方案,编译时会生成可执行二进制文件。该二进制文件依赖于另一个方案中的库,这个库是我编写的,所有相关代码也由我创建。
最近我以一种相当随意的方式尝试了许多项目设置,试图了解CLR构建和链接的工作原理。不幸的是(可预测吗?)我已经破坏了我的二进制文件的链接,但我不知道如何解决这个问题。
当我运行我的二进制文件时,应用程序在崩溃之前会给出以下反馈:
“正在加载程序集……无法添加程序集MY.Library,版本=1.0.0.0,Culture=neutral,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中找到引用?

简述:

  • 如何删除对不存在的资源DLL的引用?
3个回答

3
  • 资源是实际上嵌入在您的dll中的。您不需要引用它。
  • 如何删除对不存在资源DLL的引用?

您看到“library.resouce”的原因是您的代码通过app.configAppDomain.AssemblyResolve事件手动请求 .net 加载程序集。

在您的情况下,我认为是后者。只需找到该事件处理程序并执行以下操作:

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#。


1
我之前遇到了一个类似的问题,Visual Studio 2010 找不到各种资源 DLL,例如 xaml.resources.dll 和 presentationcore.resources.dll。最后发现是因为我把 MainWindow.xaml 移动到了子文件夹中导致的。我不知道在 Windows Forms 中是否也会出现这种情况,但对于任何使用 WPF 的人来说,请不要移动 MainWindow.xaml。又浪费了我一天的时间。

0
通常情况下,你引用的 DLL 应该在 C# 项目的 References 文件夹中(你也应该从那里添加外部 DLL)。你可以右键点击要移除的 DLL,然后选择 Remove

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