我遵循了 postsharp 1.5 附带的示例。我有两个简单的项目:
一个有这样的方面:
[Serializable]
public class MyAspectAttribute : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionEventArgs eventArgs)
{
Console.WriteLine(eventArgs.Method.Name);
base.OnEntry(eventArgs);
}
}
在另一个项目中,我有一个这样的测试用例:
public class Test
{
[MyAspect]
public void DoSomething()
{
Console.Write("aa");
}
}
在“测试”的同一个项目中,我有以下测试夹具:
[TestFixture]
public class TestFixture
{
[Test]
public void TestDoSomething()
{
var a = new Test();
a.DoSomething();
}}
由于 postsharp 异常,代码将无法编译:
Error 2 Unhandled exception: System.InvalidCastException: Unable to cast object of type 'PostSharp.CodeModel.TypeDefDeclaration' to type 'PostSharp.CodeModel.IMethod'.
at PostSharp.Laos.Weaver.MethodLevelAspectWeaver.get_TargetMethod()
at PostSharp.Laos.Weaver.MethodLevelAspectWeaver.Initialize()
at PostSharp.Laos.Weaver.OnMethodBoundaryAspectWeaver.Initialize()
at PostSharp.Laos.Weaver.LaosTask.Execute()
at PostSharp.Extensibility.Project.ExecutePhase(String phase)
at PostSharp.Extensibility.Project.Execute()
at PostSharp.Extensibility.PostSharpObject.ExecuteProjects()
at PostSharp.Extensibility.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation)
at PostSharp.MSBuild.PostSharpRemoteTask.Execute(PostSharpTaskParameters parameters, TaskLoggingHelper log) MyExample.Tests
我应该怎么办?