views:

64

answers:

3
private void ExecuteCommand(Expression<Func<bool>> command)
{
    bool success = command.Compile().Invoke();
}

private void Test()
{
    ExecuteCommand(() => _gc.ChargeCancellation(""));
}

With this code, I got a NullReferenceException.

+2  A: 

Is _gc null by any chance? Or perhaps ChargeCancellation itself is throwing the exception? It should work fine otherwise.

Jon Skeet
+1  A: 

Since you show no code to initialize _gc, my guess is that is where your NullReferenceException is happening.

Either that or something inside _gc.ChargeCancellation() is throwing the Exception.

It might help if you included the full text of the Exception so we knew exactly where the Exception was being thrown.

Justin Niessner
+2  A: 

Look through the stack trace or add a breakpoint at this line:

ExecuteCommand(() => _gc.ChargeCancellation(""));

Given the information you have posted there's no chance of anybody in this community really helping you beyond generic comments.

heads5150