SheepAspect.0.3.0.10 - (EDIT: note the sample aspect code return type!)

Feb 10, 2013 at 8:46 PM
Edited Feb 11, 2013 at 6:21 AM
Hi,
I'm running into "object reference not set to instance..." basically null reference exception while running a basic console project containing a public class with a public method via the SampleAspect provided from the Nuget install. Does the current version of 0.3.0.10 work at all or am I missing something? I can't run the most basic toy SampleAspect that comes from Nuget, so I'm wondering...

I see that the LogAroundMethod(MethodJointPoint jp) executes fully without any exception. On return from this log method the null excp happens. The call stack indicates the public method (execution join point).

I set the SheepAspect source code to launch my console POC for debugging. I found that it runs into AspectRuntime.Dispatch<TAspect> and executes the control flow from there. The target parameter is null for this method, which I believe is correct as this is an execution rather than call JP. On return from the Dispatch the debugger doesn't go into the weaved method but that's where the exception comes. This is my public method that has been weaved (the top of the stack trace) >>

public int TestMethod(string args)
{
object[] objArray = new object[] { args };
return (int) AspectRuntime.Dispatch<SampleAspect>(null, this, <>sac_TestMethod<>JpStatic.Instance, objArray);
}

This is my original public method -
public class Class1
{
    public int TestMethod(string args)
    {
        return args == null ? 0 : args.Length;
    }
}
This is the toy client -
static void Main(string[] args)
    {
        var r = new Class1().TestMethod("hollow world");
    }
Cheers!
Feb 12, 2013 at 6:28 AM
More info: Sheep throws null exception only for methods that return primitive/value types. If I change the target method's signature to
public object TestMethod(..) or public string .. then the sample aspect works.
That begs the question - does Sheep require you to define return types as reference types only to be able to use execution pointcuts? It doesnt seem to work with primitive return types for execution pointcuts.
Coordinator
Feb 12, 2013 at 6:30 AM
Hi,
Could you post the source-code of your aspect? Could you also attach the stack-trace of the exception? Could it be that your Around advice method is returning null?

Cheers
Hendry
Coordinator
Feb 12, 2013 at 6:32 AM
Edited Feb 12, 2013 at 6:32 AM
SheepAspect doesn't require your target method to return reference types, but if it returns a value type, then your Around advice mustn't return null.
Feb 12, 2013 at 6:45 AM
Hi Hendry,
yes that was the culprit. The sample aspect around advice returns void, I hadn't looked properly at the sample aspect code. I just got that hunch as well and changing it to return the same type as the target method works like a charm!
Thanks
-Rohit