我遵循了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我该怎么办?
发布于 2010-03-06 21:31:46
它看起来像是一个bug,但我想知道你的样本是如何导致这个bug的。你有没有尝试过最新的版本,或者仅仅是RTM?
如果bug没有解决,你能给support@sharpcrafters.com发送一个repro (一个独立的命令行项目)吗?
https://stackoverflow.com/questions/2387549
复制相似问题