2010-03-05 10 views
0

j'ai suivi les exemples qui viennent avec PostSharp 1.5 .. Et j'ai un deux projets simples:PostSharp erreur de compilation

On a un aspect comme celui-ci:

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

Dans l'autre projet J'ai un test comme celui-ci:

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

Dans le même projet de "test", j'ai l'appareil de test suivant:

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

Le code ne compilera pas parce qu'une exception 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 

Que dois-je faire?

Répondre

0

Cela ressemble à un bug, mais je me demande comment votre échantillon peut causer ce bug. Avez-vous essayé avec la dernière version ou juste le RTM?

Si le bug n'est pas résolu, pouvez-vous envoyer un repro (un projet de ligne de commande autonome) à [email protected]?

+0

J'étais avec le RTM, je ne sais pas .. J'ai recommencé avec une nouvelle solution à partir de zéro et ça fonctionne comme un charme. Je vais voir si je peux faire une repro. Merci –

+0

Je suis confronté au même problème avec VS 2008. PostSharp 2.0. J'ai créé un nouveau projet de bibliothèque de classes dans CS et ajouter une référence à PostSharp.dll et essayer de compiler –

+0

Même ici sous VS2010 PostSharp 2.0 Win7 x64. Assez le même code. – Maciek