PostSharp编译错误
我遵循了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它看起来像一个错误,但我想知道你的样本是如何导致这个错误的。
您尝试过最新版本还是仅使用 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]?