runtime: "Length cannot be less than zero. " thrown on nectoreapp2.0 when trying to invoke Action that accesses a property on the input class - works for anonymous types
From @maumar on June 28, 2017 19:7
repro:
public class MyEntity
{
public int Id { get; set; }
public string Name { get; set; }
}
[Fact]
public virtual void Netcoreapp_bug()
{
Action<dynamic> workingElementAsserter = e => Console.WriteLine("works");
Action<dynamic> failingElementAsserter = e => Console.WriteLine(e.Id);
var dto = new MyEntity { Id = 1, Name = "Foo" };
var anonymous = new { Id = 1, Name = "Foo" };
workingElementAsserter(dto); //works
failingElementAsserter(anonymous); //works
failingElementAsserter.Invoke(dto); //fails
}
exception:
System.ArgumentOutOfRangeException : Length cannot be less than zero.
Parameter name: length
Stack Trace:
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.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.CSharpGetMemberBinder.FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
at System.Dynamic.DynamicMetaObject.BindGetMember(GetMemberBinder binder)
at System.Dynamic.GetMemberBinder.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 Microsoft.EntityFrameworkCore.Query.ComplexNavigationsQueryTestBase`2.<>c.<Netcoreapp_bug>b__247_1(Object e)
at Microsoft.EntityFrameworkCore.Query.ComplexNavigationsQueryTestBase`2.Netcoreapp_bug()
I am unable to reproduce this in standalone app, this only happens in our test infrastructure (Entity Framework Core). Using xunit and we have generic and polymorphic test classes and tests are in multiple assemblies - maybe this has something to do with it, but so far we were unable to figure out the root cause. Let me know if you need any more info.
dotnet --version: 2.0.0-preview3-006607
Copied from original issue: dotnet/coreclr#12529
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 5
- Comments: 18 (10 by maintainers)
Commits related to this issue
- Added UrlBasedRequest class to overcome issues with .NET Core dynamic "Length cannot be less than zero." bug. See: https://github.com/dotnet/corefx/issues/21689 — committed to johnbindel/Cognitive-Vision-DotNetCore by johnbindel 7 years ago
- Fix to #8962 - External: Dynamic fails on netcoreapp2.0 Adjusting affected tests so that they no longer use dynamic Funcs. This change can be revered once/if https://github.com/dotnet/corefx/issues/2... — committed to dotnet/efcore by maumar 7 years ago
- Fix to #8962 - External: Dynamic fails on netcoreapp2.0 Adjusting affected tests so that they no longer use dynamic Funcs. This change can be revered once/if https://github.com/dotnet/corefx/issues/2... — committed to dotnet/efcore by maumar 7 years ago
- Fix bug in MS.CSharp handling non-generic classes nested in generic Such types are still generic but don't have a tick in their name, which the name lookup expects all generic types' names to have. ... — committed to JonHanna/corefx by JonHanna 7 years ago
- Fix bug in MS.CSharp handling non-generic classes nested in generic Such types are still generic but don't have a tick in their name, which the name lookup expects all generic types' names to have. ... — committed to JonHanna/corefx by JonHanna 7 years ago
- Fix bug in MS.CSharp handling non-generic classes nested in generic (#22117) Such types are still generic but don't have a tick in their name, which the name lookup expects all generic types' names ... — committed to dotnet/corefx by JonHanna 7 years ago
- Fix bug in MS.CSharp handling non-generic classes nested in generic (#22117) Such types are still generic but don't have a tick in their name, which the name lookup expects all generic types' names ... — committed to VSadov/corefx by JonHanna 7 years ago
- Merge pull request #23512 from VSadov/port21689 Porting a fix for #21689 to release/2.0.0 — committed to dotnet/corefx by weshaggard 7 years ago
- Fix bug in MS.CSharp handling non-generic classes nested in generic (#22117) Such types are still generic but don't have a tick in their name, which the name lookup expects all generic types' names ... — committed to mono/corefx by JonHanna 7 years ago
This is closed but doesn’t seem to actually be fixed in SDK 2.0.2. The PR makes it seem like it is actually in 2.0.3 which is as yet unreleased. Is this correct? Is there a release date for SDK 2.0.3?
Thanks!
On track to have it out in the next week or so.
Yeah, I think it slipped into 2.0.3. @leecow do we have public ETAs on servicing releases? Namely 2.0.3?
I’m running into this issue at the moment. What’s the correct way to swap out the Microsoft.CSharp assembly? I’ve got
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0-preview1-26666" /><PackageReference Include="Microsoft.CSharp" Version="4.4.0" />It keeps using the Microsoft.NETCore.App 2.0.0 reference library.