.net - 程序集重新编译和程序集加载问题

标签 .net .net-assembly ilasm ildasm

我有一个可执行文件(Foo.exe)和一个库Bar.dll。两个二进制文件均经过强名称签名。 Bar.dll 库依赖于可执行文件,并以如下方式在其 list 中指定它:

<dependency>
    <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Foo.exe" size="334336">
      <assemblyIdentity name="Foo" version="1.2.3.4" language="neutral" processorArchitecture="msil" />
    </dependentAssembly>
</dependency>

我使用 ildasm 和 ilasm 从 Foo.exe -> msil -> Foo.exe 进行往返。使用 ildasm 反编译会生成单个 .il 文件、.res 文件和多个 .resources 文件。我以这种方式重新编译应用程序:

ilasm Foo.il /resource=Foo.res

重新编译后,应用程序可以运行并可以启动。现在的问题是,依赖于可执行文件的库 Bar.dll 在重新编译后无法加载它(Foo.exe 可执行文件)。这就是融合日志给我的:

   *** Assembly Binder Log Entry  (11/12/2012 @ 5:00:38 PM) ***

The operation failed.
Bind result: hr = 0x8013101b. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  C:\Program Files (x86)\SomeApplication\Something.EXE
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Bartek-W7\Bartek
LOG: DisplayName = Bar, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/FooBar
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : Bar, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Application configurtion file not found.
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\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:/Program Files (x86)/FooBar/Foo.dll
LOG: Attempting download of new URL file:///C:/Program Files (x86)/FooBar/Foo/Foo.dll
LOG: Attempting download of new URL file:///C:/Program Files (x86)/FooBar/Foo.exe
LOG: Assembly download was successful. Attempting setup of file: C:/Program Files (x86)/FooBar/Foo.exe
LOG: Entering download cache setup phase.
ERR: Error extracting manifest import from file (hr = 0x8013101b).
ERR: Setup failed with hr = 0x8013101b.
ERR: Failed to complete setup of assembly (hr = 0x8013101b). Probing terminated.

现在,在重新编译之前,文件已成功加载,融合日志中的唯一区别是最后 4 行:

LOG: set name: Foo, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null
WARNING: found a duplicate set during cache setup
LOG: Bind successful.
LOG: Bind is in default load context.

最佳答案

ERR: Error extracting manifest import from file (hr = 0x8013101b)

错误代码 8013101b 是 COR_E_NEWER_RUNTIME。换句话说,程序集需要比实际加载的 CLR 版本更新的 CLR 版本。对此有一个非常简单的解释,您可能使用了错误版本的 ilasm.exe。版本 4 而不是版本 2。

一定要使用C:\Windows\Microsoft.NET\Framework\v2.0.50727\ilasm.exe,而不是v4.0.30319中的

关于.net - 程序集重新编译和程序集加载问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13823838/

相关文章:

c# - 无法找到 testhost.dll。请发布您的测试项目并重试。 (.Net 核心 2.1)

c# - 在 C++Builder 应用程序中动态加载 C# .NET 程序集

MySQL 连接器/NET 输出参数返回 NULL

c# - 使用 iTextSharp 和 C# 自动调整表格列宽

c# - 数据访问层(DAL)中的LINQ查询方法

c# - 使用 UseSetting 覆盖配置

wpf - 引用的外部命名空间与本地命名空间崩溃

.net - 为什么 ILGenerator.Emit() 在动态汇编中插入 nop 操作码?

c# - 为什么这个非常简单的 C# 方法会产生如此不合逻辑的 CIL 代码?

.net - 如何使用 Mono.Cecil 重新抛出来替换 ILAsm 抛出?