tags:

views:

126

answers:

1

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 wont 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

Thank you in advance.

A: 

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]?

Thanks.

-gael

Gael Fraiteur
I was with the RTM, I don't know.. I've started over with a new solution from scratch and it work like a charm. I'll see if I can make a repro.Thank you
José F. Romaniello
I'm facing the same issue with VS 2008. PostSharp 2.0. I created a new class library project in CS and add reference to PostSharp.dll and try to compile
usman shaheen
Same here under VS2010 PostSharp 2.0 Win7 x64. Pretty much the same code.
Maciek
Please send a small project reproducing the issue to [email protected] otherwise there's nothing I can do. Thank you.
Gael Fraiteur