如何在智能装配中合并包含PostSharp方面的装配体



我在通过SmartAssembly将包含我的PostSharp方面的程序集合并到我的项目中时遇到问题,并且想知道是否有人可以提供帮助。

主组件相当简单,看起来像:-

 class Program
{
    static void Main(string[] args)
    {
        var doer = new Doer();                
        doer.Do();
        Console.WriteLine("press any key to continue");
        Console.ReadKey();          
    }
}
[MethodDebugLogging(AttributeTargetElements = MulticastTargets.Method)]
public class Doer 
{
    public void Do()
    {
        Console.WriteLine("stuff and nonesense");
    }
}

MethodDebugLogging方面工作正常,前提是它位于同一程序集中,但将其添加到自己的程序集中,然后通过SmartAssembly合并会导致:-

System.TypeInitializationException: The type initializer for '<>z__Aspects' thre
w an exception. ---> System.TypeInitializationException: The type initializer fo
r '<>z__AspectsImplementationDetails762586886' threw an exception. ---> System.I
O.FileNotFoundException: Could not load file or assembly 'Aspects, Version=1.0.0
.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system
 cannot find the file specified.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String cod
eBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&
stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppre
ssSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName as
semblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntr
ospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evid
ence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at PostSharp.Aspects.Serialization.BinaryAspectSerializationBinder.BindToType
(String assemblyName, String typeName)
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Bind(String as
semblyString, String typeString)
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(Binary
AssemblyInfo assemblyInfo, String name)
   at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String obje
ctName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInf
ormationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, Bi
naryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWi
thMapTyped(BinaryObjectWithMapTyped record)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(He
aderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAp
pDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize
(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCr
ossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize
(Stream serializationStream, HeaderHandler handler, Boolean fCheck, IMethodCallM
essage methodCallMessage)
   at PostSharp.Aspects.Serialization.BinaryAspectSerializer.Deserialize(Stream
stream, IMetadataDispenser metadataDispenser)
   at PostSharp.Aspects.Serialization.AspectSerializer.Deserialize(Assembly asse
mbly, String resourceName, IMetadataDispenser metadataDispenser)
   at <>z__AspectsImplementationDetails762586886..cctor()
   --- End of inner exception stack trace ---
   at Obfuscation_Spike1.Doer.<>z__Aspects..cctor()
   --- End of inner exception stack trace ---
   at Obfuscation_Spike1.Doer.Do()
   at Obfuscation_Spike1.Program.Main(String[] )

而且方面本身相当简单:-

 [Serializable]
public class MethodDebugLogging :
     OnMethodBoundaryAspect
{
    public override void OnEntry(MethodExecutionArgs args)
    {
        Console.WriteLine("Entering: {0}.{1}", args.Method.DeclaringType, args.Method.Name);
    }
    public override void OnExit(MethodExecutionArgs args)
    {
        Console.WriteLine("Exiting: {0}.{1}", args.Method.DeclaringType, args.Method.Name);
    }
}

从异常来看,在我看来,当我合并包含方面的程序集时,Postsharp Distributable 的方面命名空间被剥离了,有人能够对此有所了解吗?

谢谢

保罗

使程序集易于合并的最简单方法是使用 [PSerializable] 而不是 [Serializable]

如果要继续使用 [Serializable] ,则必须在运行时配置程序集绑定。有关详细信息,请参阅 http://doc.postsharp.net/postsharp-3.0/##PostSharp-3.0.chm/html/fbd7975f-6c20-41d8-bda5-38392ed2ad00.htm。

相关内容

  • 没有找到相关文章

最新更新