简体   繁体   English

在ILMerge中使用PostSharp的问题

[英]Problems using PostSharp with ILMerge

I am creating an application that I want to ship as a single exe, or as near to as possible. 我正在创建一个要作为单个exe或尽可能接近的应用程序发布的应用程序。 Initially I tried bundling all dependencies using ILMerge, but have discovered this causes PostSharp to fail with the following exception: 最初,我尝试使用ILMerge捆绑所有依赖项,但是发现这会导致PostSharp失败,但出现以下异常:

System.TypeInitializationException: The type initializer for 'TestClass`1' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'PostSharp.ImplementationDetails_5c83534c.<>z__a_1a' threw an exception.
 ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
    at PostSharp.ImplementationDetails_5c83534c.<>z__a_1a..cctor()
    --- End of inner exception stack trace ---
    at PostSharp.ImplementationDetails_5c83534c.<>z__a_1a.Initialize()
    at TestClass`1..cctor() in :line 0

I found this blog post from 2008 on problems using PostSharp with ILMerge, but they seem to centre around a use case which has multiple libraries that use PostSharp being merged with the main exe. 我在2008年发现了一篇有关PostSharp与ILMerge一起使用的问题的博客文章 ,但它们似乎集中在一个用例上,该用例具有多个使用PostSharp与主exe合并的库。 My case is much simpler: 我的情况要简单得多:

I have a single exe that uses PostSharp, plus some third party libraries that don't use PostSharp. 我有一个使用PostSharp的exe文件,还有一些不使用PostSharp的第三方库。 The resulting exe has the same name as the original one, so I believe PostSharp should be able to find the classes. 生成的exe与原始exe具有相同的名称,因此我相信PostSharp应该能够找到这些类。

The minimal method that reproduces the problem is to just ILMerge the single exe and leave the rest of the dependencies as separate dll files. 重现此问题的最小方法是仅将单个exe合并并保留其余依赖项作为单独的dll文件。 In this toy version, ILMerge is pointless - I'm just running it over the one exe. 在此玩具版本中,ILMerge没有意义-我只是在一个exe上运行它。 However, this is enough to reproduce the problem. 但是,这足以重现该问题。

If instead of running ILMerge I just leave the original exe alone, the exception is not thrown. 如果不运行ILMerge而仅保留原始exe,则不会引发异常。 So clearly ILMerge is interfering with PostSharp somehow. 显然,ILMerge会以某种方式干扰PostSharp。 Here is the command line my build process is using: 这是我的构建过程使用的命令行:

 ilmerge /out:Releases/Prowl-a6/Prowl.exe "/lib:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5" "/targetplatform:v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5" D:\Dropbox\Code\C#\Prowl\Prowl.exe

I am using PostSharp in just one place: I have an abstract attribute class that implements MethodInterceptionAspect, and then two concrete classes that extend it. 我仅在一个地方使用PostSharp:我有一个实现MethodInterceptionAspect的抽象属性类,然后是两个扩展它的具体类。

Any ideas as to what I could do to make this work? 关于我可以做些什么的任何想法?

EDIT: After some investigation, I have discovered the error only occurs when instantiating a generic class which contains one of the MethodInterceptionAspects. 编辑:经过一番调查,我发现错误仅在实例化包含MethodInterceptionAspects之一的泛型类时发生。 Non-generic ones are fine. 非通用的也可以。 Here is a minimal solution that demonstrates the error. 是演示该错误的最小解决方案。

As suggested by @stakx, I went with an alternative to ILMerge. 正如@stakx所建议的那样,我选择了ILMerge的替代方法。 It's now working nicely with LibZ . 现在与LibZ配合良好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM