PostSharp编译错误

发布于 2024-08-24 04:34:14 字数 1604 浏览 4 评论 0原文

我遵循了 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");
    }
}

在“test”的同一个项目中,我有以下测试装置:

[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

我应该做什么?

I've followed the examples that come with postsharp 1.5 .. And I've a two simple projects:

One has an aspect like this:

[Serializable]
public class MyAspectAttribute : OnMethodBoundaryAspect
{
    public override void OnEntry(MethodExecutionEventArgs eventArgs)
    {
        Console.WriteLine(eventArgs.Method.Name);
        base.OnEntry(eventArgs);
    }
}

In the other project I've a test case like this:

public class Test
{
    [MyAspect]
    public void DoSomething()
    {
        Console.Write("aa");
    }
}

In the same project of "test", I've the following test fixture:

[TestFixture]
public class TestFixture
{
    [Test]
    public void TestDoSomething()
    {
        var a = new Test();
        a.DoSomething();
    }}

The code won't compile because a postsharp exception:

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

What should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

度的依靠╰つ 2024-08-31 04:34:14

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

如果错误没有解决,您可以将重现(一个独立的命令行项目)发送到 [电子邮件受保护]

It looks as a bug, but I wonder how your sample can cause this bug.
Did you try with the latest build or just the RTM?

If the bug is not solved, can you send a repro (a self-contained command-line project) to [email protected]?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文