_From @DavidZidar on August 18, 2017 22:45_
I've discovered a regression where calling a generic method with a dynamic argument throws an exception in .NET Core 2.0 but not in previous versions.
Here is a small program that cause the bug.
https://github.com/DavidZidar/DynamicProblems/blob/ad51939ec05bd840bf441e9653d6fb608872e6ce/DynamicProblems/Program.cs#L7-L36
The problematic type signature is as follows void HandleMessage<TResult>(IQuery<TResult> query)
As you can see in the example, invoking the method with TResult of List<> works fine but with ImmutableList<> the runtime binder throws the following exception.
Length cannot be less than zero.
Parameter name: length
at System.String.Substring(Int32 startIndex, Int32 length)
at Microsoft.CSharp.RuntimeBinder.Syntax.NameTable.Add(String key, Int32 length)
at Microsoft.CSharp.RuntimeBinder.Syntax.NameManager.Add(String key, Int32 length)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.GetName(Type type)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.LoadSymbolsFromType(Type originalType)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.GetConstructedType(Type type, AggregateSymbol agg)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.LoadSymbolsFromType(Type originalType)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.GetCTypeArrayFromTypes(IList`1 types)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.SetInterfacesOnAggregate(AggregateSymbol aggregate, Type type)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.AddAggregateToSymbolTable(NamespaceOrAggregateSymbol parent, Type type)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.LoadSymbolsFromType(Type originalType)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.GetConstructedType(Type type, AggregateSymbol agg)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.LoadSymbolsFromType(Type originalType)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.GetCTypeArrayFromTypes(IList`1 types)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.SetInterfacesOnAggregate(AggregateSymbol aggregate, Type type)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.AddAggregateToSymbolTable(NamespaceOrAggregateSymbol parent, Type type)
at Microsoft.CSharp.RuntimeBinder.SymbolTable.LoadSymbolsFromType(Type originalType)
at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.GetArgumentType(ICSharpBinder p, CSharpArgumentInfo argInfo, Expression param, DynamicMetaObject arg, Int32 index)
at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.CreateArgumentArray(ICSharpBinder payload, Expression[] parameters, DynamicMetaObject[] args)
at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.BindCore(ICSharpBinder payload, Expression[] parameters, DynamicMetaObject[] args, DynamicMetaObject& deferredBinding)
at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.Bind(DynamicMetaObjectBinder payload, Expression[] parameters, DynamicMetaObject[] args, DynamicMetaObject& deferredBinding)
at Microsoft.CSharp.RuntimeBinder.BinderHelper.Bind(DynamicMetaObjectBinder action, RuntimeBinder binder, DynamicMetaObject[] args, IEnumerable`1 arginfos, DynamicMetaObject onBindingError)
at Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder.FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
at System.Dynamic.DynamicMetaObject.BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
at System.Dynamic.InvokeMemberBinder.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.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
at DynamicProblems.Program.Main(String[] args) in c:\code\test\DynamicProblems\DynamicProblems\Program.cs:line 27
If you change TargetFramework to netcoreapp1.1 in the csproj file then everything works as expected.
_Copied from original issue: dotnet/coreclr#13478_
https://github.com/dotnet/corefx/issues/21689
This should be fixed in the final version .NET Core 2.0. Are you running against preview?
cc @VSadov @JonHanna
_From @DavidZidar on August 18, 2017 23:0_
No, I'm running RTM.
This should be fixed in the final version .NET Core 2.0. Are you running against preview?
This was fixed by dotnet/corefx#22117, which was after 2.0.
@VSadov I think we should port the fix to 2.0.x servicing release.
I haven't seen this one come to shiproom for 2.0.2. Is that the goal?
@Petermarcu - see: https://github.com/dotnet/corefx/pull/23512
I did notify the shiproom for 2.0.1, but it was below the bar at that point.
I probably should ping them again to not forget this for 2.0.2
Most helpful comment
@VSadov I think we should port the fix to 2.0.x servicing release.