2

PostSharp アスペクトを含むアセンブリを SmartAssembly を介してプロジェクトにマージする際に問題が発生し、誰か助けてくれるかどうか疑問に思っていました。

メイン アセンブリはかなり単純で、次のようになります。

 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 のアスペクト名前空間が取り除かれるように見えますが、誰かがこれに光を当てることができますか?

ありがとう

ポール

4

1 に答える 1

1

アセンブリを簡単にマージ可能にする最も簡単な方法は、[PSerializable]代わりに を使用することです[Serializable]

を引き続き使用する[Serializable]場合は、実行時にアセンブリ バインディングを構成する必要があります。詳細については、 http://doc.postsharp.net/postsharp-3.0/##PostSharp-3.0.chm/html/fbd7975f-6c20-41d8-bda5-38392ed2ad00.htmを参照してください。

于 2013-09-06T12:05:18.107 に答える