nsubstitute/NSubstitute — Issue #61: Stub any string and pass null throws null ref from NSub (1.2)
Author: dtchepak
Created: 2011-10-09 09:24:55+00:00
State: open

````csharp
public interface IFoo { string Bar(string a, double b); }

[Test]
public void Stub_any_string_and_call_with_null()
{
var foo = Substitute.For();
foo.Bar(Arg.Any(), Arg.Any()).ReturnsForAnyArgs("hello");

Assert.AreEqual("hello", foo.Bar(null, 0));
}

````

````
System.NullReferenceException : Object reference not set to an instance of an object.
at System.Object.GetType()
at NSubstitute.Core.CallSpecification.RunActionIfTypeIsCompatible(Object argument, Action`1 action, Type requiredType) in CallSpecification.cs: line 78
at NSubstitute.Core.CallSpecification.<>c__DisplayClass9.b__8(Object x) in CallSpecification.cs: line 71
at NSubstitute.Core.CallSpecification.InvokePerArgumentActions(CallInfo callInfo) in CallSpecification.cs: line 62
at NSubstitute.Core.CallActions.CallAction.Invoke(CallInfo callInfo) in CallActions.cs: line 59
at NSubstitute.Core.CallActions.InvokeMatchingActions(ICall call) in CallActions.cs: line 41
at NSubstitute.Routing.Handlers.DoActionsCallHandler.Handle(ICall call) in DoActionsCallHandler.cs: line 16
at NSubstitute.Routing.Route.<>c__DisplayClass3.b__0(ICallHandler x) in Route.cs: line 18
at System.Linq.Enumerable.<>c__DisplayClass12`3.b__11(TSource x)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate)
at NSubstitute.Routing.Route.Handle(ICall call) in Route.cs: line 18
at NSubstitute.Core.CallRouter.Route(ICall call) in CallRouter.cs: line 53
at NSubstitute.Proxies.CastleDynamicProxy.CastleForwardingInterceptor.Intercept(IInvocation invocation) in CastleForwardingInterceptor.cs: line 22
at Castle.DynamicProxy.AbstractInvocation.Proceed() in e:\OSS.Code\Castle.Core\src\Castle.Core\DynamicProxy\AbstractInvocation.cs: line 168
at Castle.Proxies.IFooProxy.Bar(String a, Double b)
at NSubstitute.Acceptance.Specs.FieldReports.ArgAnyStringRegression.Stub_any_string_and_call_with_null() in ArgAnyStringRegression.cs: line 15
````