2010-03-05 58 views
0

我已經遵循了postsharp 1.5的例子。而我有一個兩個簡單的項目:PostSharp編譯錯誤

一個具有這樣一個方面:

[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 

我該怎麼辦?

回答

0

它看起來像一個錯誤,但我不知道你的示例如何導致這個錯誤。 您是使用最新版本還是隻使用RTM?

如果這個錯誤沒有解決,您可以發送一個repro(一個獨立的命令行項目)到[email protected]嗎?

+0

我與RTM,我不知道..我從頭開始了一個新的解決方案,它的工作就像一個魅力。我會看看我是否可以製作一個repro。 謝謝 – 2010-03-07 11:06:13

+0

我正面臨着與VS 2008相同的問題。PostSharp 2.0。我在CS中創建了一個新的類庫項目並添加對PostSharp.dll的引用並嘗試編譯 – 2010-04-06 13:04:20

+0

在VS2010 PostSharp 2.0 Win7 x64下也是如此。幾乎相同的代碼。 – Maciek 2010-09-11 12:56:44