1

Closed

Aspect code can't be executed

description

I'm facing a problem in implementing aspect code, the application works great but it can't execute the aspect class, only the target class executed. I tried to uninstall Rapier-LOOM and install it again but it doesn't work. Also I tried to attach Rapier references but also it doesn't make any sound. I don't know how can I solve this problem?'
 
this is the aspect class:
 
using System;
using Loom;
using Loom.JoinPoints;
namespace HelloAspect
{
public class TraceAspect : Aspect
{
    [Loom.JoinPoints.Exclude("ToString")]
    [Call(Advice.Around)]
 
    public T Trace<T>([JPContext]Context ctx, params object[] args)
    {
        Console.WriteLine(ctx.Instance + "." + ctx.CurrentMethod.Name + " called");
 
        ctx.Invoke(args);
        return default(T);
    }
}
}
 
this is the Application:
 
using System;
using Loom;
using Loom.JoinPoints;
 
namespace HelloAspect
{
class Program
{
    static void Main(string[] args)
    {
             string name;
             Console.Write("Your name: ");
             name = Console.ReadLine();
             TraceAspect aspect1 = new TraceAspect();
             Target target = Loom.Weaver.Create<Target>(aspect1);
             target.Hello(name);
             Console.ReadLine();   
    }
}
}
 
the Target class is:
 
public class Target
{
    public virtual void Hello(string name)
    {
        Console.WriteLine("Hello {0}!", name);
    }
}

file attachments

Closed Dec 27, 2011 at 3:39 PM by wschult
The problem is, that the example in the Loom documentation is wrong: If you access the Instance of a joinpoint context with a subsequent ToString call, then the joinpoint will be executed recursivly until a StackOverflow exception occours.

comments

areeg wrote Dec 29, 2011 at 7:50 AM

I tried to solve the problem and here is the code that solve it

Aspect class:

public void Hello([JPContext]Context ctx, params object[] args)
    {
        Console.WriteLine("{0}.{1} called", ctx.TargetClass, ctx.CurrentMethod.Name);
    }

wrote Feb 14, 2013 at 6:16 PM

wrote May 16, 2013 at 8:10 AM