This project is read-only.


unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll


every time I run my project this Error occur in the following statement:
Console.WriteLine("{0}.{1}aspect method called ",ctx.Instance, ctx.CurrentMethod.Name);
and say "An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll"
How can i fix this problem?

file attachments

Closed Dec 16, 2011 at 7:50 PM by wschult
It is not a bug, see my comments.


wschult wrote Dec 16, 2011 at 7:46 PM

In your example your join-point ist interwoven with each method of the target class. This implies, that the ToString() method is interwoven with the join point. When you call the ctx.Instance property then the interwoven ToString() method will be callend and so your join point will be invoked again.
Now it depends, what you want:
Option 1: If you are only interested in the type of the interwoven class, then use ctx.TargetClass
Option 2: You could exclude the ToString() method by adding
to your join-point declaration.
Option 3: You could add the [Loom.JoinPoints.IncludeDeclaredOnly] to your join point method. This would mean, that only methods declared in the target class will be interwoven.
Option 4: You could programatically add an "in join-point gate" to prevent reentrant join-point calls:
public class AspectClass : Loom.Aspect
public T Trace<T>([JPContext] Context ctx, [JPVariable(Scope.Call)] ref bool gate, params object[] args)
    if (!gate)
        gate = true;
        Console.WriteLine("{0}.{1}aspect method called ", ctx.Instance, ctx.CurrentMethod.Name);
        gate = false;
    return default(T);

wrote Dec 16, 2011 at 7:48 PM

wrote Dec 16, 2011 at 7:50 PM

wrote Feb 14, 2013 at 7:16 PM

wrote May 16, 2013 at 9:10 AM