
moq - issue #376
NullReferenceException thrown by Microsoft.CSharp when using Generic Interfaces and Dynamic
What steps will reproduce the problem? 1. Run the attached program 2. 3.
What is the expected output? What do you see instead? Throws an exception when using a mock'd implementation of a generic interface, ok when using a non-generic interface.
What version of the product are you using? On what operating system? Win7, Moq 4.2.1402.2112, .NET 4.5.1
Please provide any additional information below. Full Error: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.GenerateLambda(EXPRCALL pExpr) at Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.VisitCALL(EXPRCALL pExpr) at Microsoft.CSharp.RuntimeBinder.Semantics.ExprVisitorBase.Dispatch(EXPR pExpr) at Microsoft.CSharp.RuntimeBinder.Semantics.ExprVisitorBase.Visit(EXPR pExpr) at Microsoft.CSharp.RuntimeBinder.ExpressionTreeCallRewriter.Rewrite(TypeManager typeManager, EXPR pExpr, IEnumerable`1 listOfParameters)
at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.CreateExpressionTreeFromResult(IEnumerable1 parameters, ArgumentObject[] arguments, Scop
e pScope, EXPR pResult)
at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.BindCore(DynamicMetaObjectBinder payload, IEnumerable
1 parameters, DynamicMetaObject[] a
rgs, DynamicMetaObject& deferredBinding)
at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.Bind(DynamicMetaObjectBinder payload, IEnumerable1 parameters, DynamicMetaObject[] args,
DynamicMetaObject& deferredBinding)
at Microsoft.CSharp.RuntimeBinder.BinderHelper.Bind(DynamicMetaObjectBinder action, RuntimeBinder binder, IEnumerable
1 args, IEnumerable
1 arginfos, DynamicMetaObject onBindingError)
at Microsoft.CSharp.RuntimeBinder.CSharpConvertBinder.FallbackConvert(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
at System.Dynamic.DynamicMetaObject.BindConvert(ConvertBinder binder)
at System.Dynamic.ConvertBinder.Bind(DynamicMetaObject target, DynamicMetaObject[] args)
at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection
1 parameters, LabelTarget returnLabel)
at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite1 site, Object[] args)
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at TestDynamic.Program.GenericDoStuffDynamic[T](IInterface
1 obj, T input) in c:\TFS\TestProjects\TestDynamic\TestDynamic\Program.cs:line
37
at TestDynamic.Program.Main(String[] args) in c:\TFS\TestProjects\TestDynamic\TestDynamic\Program.cs:line 27
- Program.cs 1.41KB
Comment #1
Posted on Jun 6, 2014 by Massive WombatThe exception only seems to happen when the generic type parameter is object. I've tested with value types (Guid, int) and custom reference type they all work.
Status: New
Labels:
Type-Defect
Priority-Medium