PostSharp编译错误

时间:2010-03-05 14:51:39

标签: c# postsharp

我已经跟随了postharp 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();
    }}

代码将无法编译,因为postharp异常:

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

我该怎么办?

1 个答案:

答案 0 :(得分:0)

它看起来像一个bug,但我想知道你的样本如何导致这个bug。 您尝试使用最新版本还是仅使用RTM?

如果错误未解决,您可以将repro(一个自包含的命令行项目)发送到support@sharpcrafters.com吗?