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

时间:2012-12-11 16:06:47

标签: .net .net-assembly ilasm ildasm

我有一个可执行文件(Foo.exe)和一个库Bar.dll。这两个二进制文件都是 NOT 强名称签名。 Bar.dll库依赖于可执行文件,并以其方式在其清单中指定:

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

我从Foo.exe进行往返 - &gt; msil - &gt; Foo.exe与ildasm和ilasm。使用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.

1 个答案:

答案 0 :(得分:4)

  

错误:从文件中提取清单导入时出错(hr = 0x8013101b)

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

请务必使用C:\ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ ilasm.exe,而不是v4.0.30319中的那个