RajOpteamix / moq

Automatically exported from code.google.com/p/moq
Other
0 stars 0 forks source link

NullReferenceException thrown by Microsoft.CSharp when using Generic Interfaces and Dynamic #376

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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(IEnumerable`1 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, IEnumerable`1 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](CallSite`1 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

Original issue reported on code.google.com by amit.gos...@gmail.com on 6 Jun 2014 at 12:41

Attachments:

GoogleCodeExporter commented 9 years ago
The 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.

Original comment by amit.gos...@gmail.com on 6 Jun 2014 at 12:59