Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Length cannot be less than zero. " thrown on nectoreapp2.0 when trying to invoke Action<dynamic> that accesses a property on the input class - works for anonymous types #22544

Closed
jkotas opened this issue Jun 29, 2017 · 18 comments

Comments

@jkotas
Copy link
Member

jkotas commented Jun 29, 2017

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

@jkotas
Copy link
Member Author

jkotas commented Jun 29, 2017

From @maumar on June 28, 2017 19:22

In order to actually reproduce the issue:

clone https://github.com/aspnet/EntityFramework/tree/netcoreapp_bug
run dotnet restore on the solution
navigate to \test\EFCore.InMemory.FunctionalTests
run dotnet test --framework netcoreapp2.0 --filter FullyQualifiedName~Netcoreapp_bug

johnbindel referenced this issue in johnbindel/Cognitive-Vision-DotNetCore Jul 3, 2017
maumar referenced this issue in dotnet/efcore Jul 3, 2017
Adjusting affected tests so that they no longer use dynamic Funcs. This change can be revered once/if https://github.com/dotnet/corefx/issues/21689 is fixed
maumar referenced this issue in dotnet/efcore Jul 3, 2017
Adjusting affected tests so that they no longer use dynamic Funcs. This change can be revered once/if https://github.com/dotnet/corefx/issues/21689 is fixed
JonHanna referenced this issue in JonHanna/corefx Jul 11, 2017
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.

Handle this case correctly.

Fixes #21689
JonHanna referenced this issue in JonHanna/corefx Jul 11, 2017
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.

Handle this case correctly.

Fixes #21689
@JonHanna
Copy link
Contributor

at Microsoft.EntityFrameworkCore.Query.ComplexNavigationsQueryTestBase`2.Netcoreapp_bug()`

There's the rub. Because the entity class is nested in a generic class, it's a generic type, but because it doesn't have type parameters itself there's no tick in its name, but I'm afraid that changes I made to SymbolTable.GetName assume otherwise.

VSadov referenced this issue in dotnet/corefx Jul 20, 2017
…22117)

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.

Handle this case correctly.

Fixes #21689
@matt-psaltis
Copy link

matt-psaltis commented Aug 18, 2017

I'm running into this issue at the moment. What's the correct way to swap out the Microsoft.CSharp assembly? I've got

  • Dotnet core sdk: 2.1.0-preview1-007055
  • Target framework: netcoreapp2.0
  • <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.

@jbtule
Copy link

jbtule commented Aug 19, 2017

Looking at the merge the fix for this is in Microsoft.CSharp. So is there a patched version of it available somewhere, alternative nuget feed?

@matt-psaltis
Copy link

I'm trying to use this one here: https://dotnet.myget.org/feed/aspnetcore-dev/package/nuget/Microsoft.CSharp/4.4.0

Just don't know how to get this to be picked up by the module loading instead of the 2.0.0 reference library. It shows up in the NuGet project tree but at runtime the loaded modules view in visual studio shows the 2.0.0 assembly instead.

@danmoseley
Copy link
Member

@weshaggard how should they force it to pick up the 2.1 assembly?

@weshaggard
Copy link
Member

If all you are after is an updated Microsoft.CSharp library (not sure if that is all that is needed as I'm sure about this full issue), you can get it from our dotnet-core feed https://dotnet.myget.org/feed/dotnet-core/package/nuget/Microsoft.CSharp/4.5.0-preview2-25621-02.

@jbtule
Copy link

jbtule commented Aug 22, 2017

Thanks @weshaggard, while indeed that version of the nuget package, does contain the fix for other platforms (decompiled it to verify), it's a no-op for netcoreapp 2.0 😑

@weshaggard
Copy link
Member

For .NET Core 2.0 it is included in the shared framework package as opposed to the individual library package. You will need to follow the dogfooding instructions https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/dogfooding.md to consume a prerelease version of the shared framework with the fix. RuntimeFrameworkVersion is the key property that will need to be updated.

@matt-psaltis
Copy link

Thanks @weshaggard that looks like the missing piece of the puzzle. Thanks for that.

VSadov referenced this issue in VSadov/corefx Aug 23, 2017
…otnet#22117)

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.

Handle this case correctly.

Fixes #21689
@karelz
Copy link
Member

karelz commented Sep 8, 2017

Reopening to track 2.0.x port.

@karelz karelz reopened this Sep 8, 2017
weshaggard referenced this issue in dotnet/corefx Sep 8, 2017
Porting a fix for #21689 to release/2.0.0
@karelz
Copy link
Member

karelz commented Sep 8, 2017

Fixed for 2.0.2 2.0.3 servicing in PR dotnet/corefx#23512

@karelz karelz closed this as completed Sep 8, 2017
marek-safar referenced this issue in mono/corefx Oct 12, 2017
…otnet#22117)

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.

Handle this case correctly.

Fixes #21689
@bungeemonkee
Copy link

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!

@karelz
Copy link
Member

karelz commented Nov 6, 2017

Yeah, I think it slipped into 2.0.3. @leecow do we have public ETAs on servicing releases? Namely 2.0.3?

@leecow
Copy link
Member

leecow commented Nov 7, 2017

On track to have it out in the next week or so.

@eddiezane
Copy link

2.0.3 shipped and fixes the issue for me!

Great work by the team 🎉

@VSadov
Copy link
Member

VSadov commented Nov 16, 2017

CC: @jaredpar

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.x milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests