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

System.ArgumentOutOfRangeException after upgrade to EF Core 2.0 #10045

Closed
joshmouch opened this issue Oct 11, 2017 · 12 comments
Closed

System.ArgumentOutOfRangeException after upgrade to EF Core 2.0 #10045

joshmouch opened this issue Oct 11, 2017 · 12 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@joshmouch
Copy link

joshmouch commented Oct 11, 2017

After upgrading from EF Core 1.1 to 2.0, I started getting an exception when a certain query executes.

The code is along the lines of:

var recordsQuery = dataContext.Entities
				.Include(ar => ar.A)
				.Include(ar => ar.B)
				.Include(ar => ar.C.D)   <---- COMMENTING OUT MAKES EXCEPTION GO AWAY
.Where(ar => ... simple filter ...);

recordsQuery  = recordsQuery .Where(ar => ... simple filter ...);

recordsQuery = recordsQuery.OrderBy(ar => ar.A); // <---- COMMENTING OUT THIS LINE MAKES EXCEPTION GO AWAY

var hasAny = recordsQuery.Any(); // <-- THIS LINE *DOES NOT* THROW EXCEPTION
var records = await recordsQuery.ToListAsync();  // <--- THIS LINE THROWS EXCEPTION

If I comment out the line that adds an OrderBy and a ThenBy to the query, the exception goes away.
Also, if I comment out the Include calls, the exception goes away.

The exception is:

System.ArgumentOutOfRangeException occurred
  HResult=0x80131502
  Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  Source=<Cannot evaluate the exception source>
  StackTrace:
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.BindSubqueryProjectionIndex(Int32 projectionIndex, IQuerySource querySource)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Remotion.Linq.Parsing.ThrowingExpressionVisitor.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitOrderByClause(OrderByClause orderByClause, QueryModel queryModel, Int32 index)
   at Remotion.Linq.Clauses.OrderByClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
   at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
   at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitSubQuery(SubQueryExpression expression)
   at Remotion.Linq.Clauses.Expressions.SubQueryExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression`1 node)
   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
   at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node)
   at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitConditional(ConditionalExpression node)
   at System.Linq.Expressions.ConditionalExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression`1 node)
   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitNewArray(NewArrayExpression node)
   at System.Linq.Expressions.NewArrayExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node)
   at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression`1 node)
   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMember(MemberExpression node)
   at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
   at Remotion.Linq.Clauses.SelectClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel)
   at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateAsyncQueryExecutor[TResult](QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileAsyncQuery[TResult](QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQueryCore[TResult](Expression query, INodeTypeProvider nodeTypeProvider, IDatabase database)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass24_0`1.<CompileAsyncQuery>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddAsyncQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQuery[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.System.Collections.Generic.IAsyncEnumerable<TResult>.GetEnumerator()
   at System.Linq.AsyncEnumerable.<Aggregate_>d__6`3.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

@ajcvickers
Copy link
Member

Assigning to @smitpatel to investigate:

  • Dupes
  • Workarounds
  • Whether or not it meets the bar for a patch

@smitpatel
Copy link
Member

@joshmouch - Can you post exact ordering line?
Duplicate of #9499

@joshmouch
Copy link
Author

In my case, I'm not doing any type of casting. The ordering line looks like this, where the "Id" property is of type Int32:

recordsQuery = recordsQuery.OrderBy(ar => ar.Id);

@joshmouch
Copy link
Author

Another difference with #9499 is that in my case, I can use the Include and OrderBy unless I try to Include a Navigation property of a Navigation property.
So either:

.Include(a => a.B).ThenInclude(b => b.C)
or
.Include(a => a.B.C)

@smitpatel
Copy link
Member

Here is the repro code I used. I am not seeing any exception. Please modify the code so that it can show exception you are seeing.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

namespace EFSampleApp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            using (var db = new MyContext())
            {
                // Recreate database
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();

                // Seed database


                db.SaveChanges();
            }

            using (var db = new MyContext())
            {
                // Run queries
                var query = db.Entities
                    .Include(ar => ar.A)
                    .Include(ar => ar.B)
                    .Include(ar => ar.C.D)
                    .Where(ar => ar.Predicate == 1)
                    .OrderBy(ar => ar.Id)
                    .ToList();
            }

            Console.WriteLine("Program finished.");
        }
    }


    public class MyContext : DbContext
    {
        // Declare DBSets
        public DbSet<Entity> Entities { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            // Select 1 provider
            optionsBuilder
                .UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=_ModelApp;Trusted_Connection=True;Connect Timeout=5;ConnectRetryCount=0")
                //.UseSqlite("filename=_modelApp.db")
                //.UseInMemoryDatabase(databaseName: "_modelApp")
                .EnableSensitiveDataLogging()
                .UseLoggerFactory(new LoggerFactory().AddConsole(LogLevel.Trace));
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // Configure model
        }
    }

    public class Entity
    {
        public int Id { get; set; }
        public int Predicate { get; set; }
        public List<A> A { get; set; }
        public List<B> B { get; set; }
        public C C { get; set; }
    }

    public class A
    {
        public int Id { get; set; }
    }

    public class B
    {
        public int Id { get; set; }
    }

    public class C
    {
        public int Id { get; set; }
        public int EntityId { get; set; }
        public List<D> D { get; set; }
    }

    public class D
    {
        public int Id { get; set; }
    }
}

@joshmouch
Copy link
Author

joshmouch commented Oct 11, 2017

I tried to take your code and change it to as close as possible to my model, and I'm not reproducing it that way, either. Here's my code, below. Is there something else I can try to help you reproduce it?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

namespace ConsoleApp1
{

	public class Program
	{
		public static void Main(string[] args)
		{
			using (var db = new MyContext())
			{
				// Recreate database
				db.Database.EnsureDeleted();
				db.Database.EnsureCreated();

				// Seed database


				db.SaveChanges();
			}

			using (var db = new MyContext())
			{
				// Run queries
				var query = db.Fours
					.Include(ar => ar.Fives)
					.Include(ar => ar.Two)
					.ThenInclude(pf => pf.Threes)
					.OrderBy(ar => ar.Id)
					.Take(100)
					;

				var results = query.ToList();
			}

			Console.WriteLine("Program finished.");
		}
	}


	public class MyContext : DbContext
	{
		// Declare DBSets
		public DbSet<One> Ones { get; set; }
		public DbSet<Two> Twos { get; set; }
		public DbSet<Three> Threes { get; set; }
		public DbSet<Four> Fours { get; set; }
		public DbSet<Five> Fives { get; set; }

		protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
		{
			// Select 1 provider
			optionsBuilder
				.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=_ModelApp;Trusted_Connection=True;Connect Timeout=5;ConnectRetryCount=0")
				//.UseSqlite("filename=_modelApp.db")
				//.UseInMemoryDatabase(databaseName: "_modelApp")
				.EnableSensitiveDataLogging()
				.UseLoggerFactory(new LoggerFactory().AddConsole(LogLevel.Trace));


		}

		protected override void OnModelCreating(ModelBuilder modelBuilder)
		{
			// Configure model
			modelBuilder.Entity<Five>()
				.HasKey(a => new { a.OneId, a.FourId, a.Id });

			modelBuilder.Entity<Five>()
				.Property(a => a.Id)
				.ValueGeneratedOnAdd();

			modelBuilder.Entity<Five>()
				.HasOne(a => a.One)
				.WithMany()
				.HasForeignKey(a => a.OneId)
				.OnDelete(DeleteBehavior.Restrict)
				;

			modelBuilder.Entity<Five>()
				.HasOne(a => a.ParentFour)
				.WithMany(b => b.Fives)
				.HasForeignKey(a => new { a.OneId, a.Id })
				.OnDelete(DeleteBehavior.Restrict)
				;

			modelBuilder.Entity<Four>()
				.HasKey(a => new { a.OneId, a.Id });

			modelBuilder.Entity<Four>()
				.Property(a => a.Id)
				.ValueGeneratedOnAdd();

			modelBuilder.Entity<Four>()
				.HasOne(a => a.Two)
				.WithMany()
				.HasForeignKey(a => new { a.OneId, a.TwoId })
				.OnDelete(DeleteBehavior.Cascade)
				;

			modelBuilder.Entity<Four>()
				.HasOne(a => a.One)
				.WithMany((Expression<Func<One, IEnumerable<Four>>>)null)
				.HasForeignKey(a => a.OneId)
				.OnDelete(DeleteBehavior.Restrict)
				;

			//[DeletedOn], [TwoId], [OneId]
			modelBuilder.Entity<Four>()
				.HasIndex(ar => new { DeletedOn = ar.Predicate1, ar.OneId, ar.TwoId });
			modelBuilder.Entity<Four>()
				.HasIndex(ar => new { DeletedOn = ar.Predicate1, ar.OneId, ar.Predicate2, ar.Predicate3 });

			modelBuilder.Entity<One>()
				.HasKey(a => a.Id);
			modelBuilder.Entity<One>()
				.Property(a => a.Id)
				.ValueGeneratedOnAdd();

			modelBuilder.Entity<Two>()
				.HasKey(a => new { a.OneId, a.Id });

			modelBuilder.Entity<Two>()
				.Property(a => a.Id)
				.ValueGeneratedOnAdd();

			modelBuilder.Entity<Two>()
				.HasOne(a => a.One)
				.WithMany((Expression<Func<One, IEnumerable<Two>>>)null)
				.HasForeignKey(a => a.OneId)
				.OnDelete(DeleteBehavior.Restrict)
				;

			modelBuilder.Entity<Three>()
				.HasKey(a => new { a.OneId, a.Id });

			modelBuilder.Entity<Three>()
				.Property(a => a.Id)
				.ValueGeneratedOnAdd();


			modelBuilder.Entity<Three>()
				.HasOne(a => a.One)
				.WithMany((Expression<Func<One, IEnumerable<Three>>>)null)
				.HasForeignKey(a => a.OneId)
				.OnDelete(DeleteBehavior.Restrict)
				;

			modelBuilder.Entity<Three>()
				.HasOne(a => a.Two)
				.WithMany(b => b.Threes)
				.HasForeignKey(a => new { a.OneId, a.TwoId })
				.OnDelete(DeleteBehavior.Restrict)
				;
		}
	}

	public class One
	{
		public int Id { get; set; }
	}

	public class Two
	{
		public int Id { get; set; }
		public int OneId { get; set; }

		public virtual One One { get; set; }
		public ICollection<Three> Threes { get; set; }

	}

	public class Three
	{
		public int Id { get; set; }
		public int TwoId { get; set; }
		public int OneId { get; set; }
		public Two Two { get; set; }
		public virtual One One { get; set; }
	}

	public class Four
	{
		public int Id { get; set; }
		public int OneId { get; set; }
		public int TwoId { get; set; }
		public DateTime? Predicate1 { get; set; }
		public bool Predicate2 { get; set; }
		public string Predicate3 { get; set; }

		public virtual ICollection<Five> Fives { get; set; }
		public virtual Two Two { get; set; }
		public virtual One One { get; set; }
	}

	public class Five
	{
		public int Id { get; set; }
		public int FourId { get; set; }
		public int OneId { get; set; }

		public Four ParentFour { get; set; }
		public virtual One One { get; set; }
	}



}

@smitpatel
Copy link
Member

@joshmouch - The root cause of the linked issue which gives same stack-trace is the collection Include & Order By clause together.

The Include sends 2 queries. 2nd query is to fetch related data. To correlate data better, both the queries are ordered by Principal key of relationship. If user-specified OrderBy co-incide with it, then it should resolve to same ordering and not add extra. But when that goes wrong then we have 2 orderings in query which would translate to same sql and above exception will be thrown due to mismatch in numbers.

@smitpatel
Copy link
Member

Got repro.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

namespace EFSampleApp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            using (var db = new MyContext())
            {
                // Recreate database
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();

                // Seed database


                db.SaveChanges();
            }

            using (var db = new MyContext())
            {
                // Run queries
                var query = db.Users.Include(u => u.Blog.Posts).OrderBy(e => e.Blog.Id2).ToList();
            }

            Console.WriteLine("Program finished.");
        }
    }


    public class MyContext : DbContext
    {
        // Declare DBSets
        public DbSet<User> Users { get; set; }
        public DbSet<Blog> Blogs { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            // Select 1 provider
            optionsBuilder
                .UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=_ModelApp;Trusted_Connection=True;Connect Timeout=5;ConnectRetryCount=0")
                //.UseSqlite("filename=_modelApp.db")
                //.UseInMemoryDatabase(databaseName: "_modelApp")
                .EnableSensitiveDataLogging()
                .UseLoggerFactory(new LoggerFactory().AddConsole(LogLevel.Trace));
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // Configure model
            modelBuilder.Entity<Blog>(b =>
            {
                b.HasKey(e => new {e.Id1, e.Id2});
                b.HasMany(e => e.Posts).WithOne().HasForeignKey(e => new {e.BlogId1, e.BlogId2});
            });
        }
    }

    public class User
    {
        public int Id { get; set; }
        public Blog Blog { get; set; }
    }

    public class Blog
    {
        public int UserId { get; set; }
        public int Id1 { get; set; }
        public int Id2 { get; set; }
        public List<Post> Posts { get; set; }
    }

    public class Post
    {
        public int Id { get; set; }
        public int BlogId1 { get; set; }
        public int BlogId2 { get; set; }
    }
}

It happens when you do 2nd level collection include and order by key off reference navigation. I also know where the fix will be.

@smitpatel
Copy link
Member

The issue is navigation rewrite & Include both will try to add ordering on same property e.Blog.Id2. They don't end up being same in query model and later gets collapsed in SQL throwing exception. We need to improve our logic to find matching existing ordering. It would be small fix and very low risk.

@ajcvickers
Copy link
Member

@smitpatel This is approved; can we get a PR out for it this morning?

smitpatel added a commit that referenced this issue Oct 12, 2017
…iler with existing ordering

Resolves #10045

The issue: When you have reference.collection include and orderby reference.property, the ordering is expanded by navigation rewrite and it is null-compensated. Whereas the ordering collection include adds missed null-compensation hence they were not matching property causing multiple orderings/projection in QueryModel, which would map to same SqlFragment causing projection count mismatch.
The fix is to unique-fy ordering by including null-compensation. Due to new pattern generated by Include, downstream code needs to understand & match more patterns.
smitpatel added a commit that referenced this issue Oct 12, 2017
smitpatel added a commit that referenced this issue Oct 12, 2017
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 12, 2017
@Eilon
Copy link
Member

Eilon commented Oct 23, 2017

Hi, we have a public test feed that you can use to try out the ASP.NET/EF Core 2.0.3 patch!

To try out the pre-release patch, please refer to the following guide:

We are looking for feedback on this patch. We'd like to know if you have any issues with this patch by updating your apps and libraries to the latest packages and seeing if it fixes the issues you've had, or if it introduces any new issues. If you have any issues or questions, please reply on this issue to let us know as soon as possible.

Thanks,
Eilon

@adrianotrentim
Copy link

Dear, first, excuse my English.

I found a similar error.

Follow steps to simuate:

var query = db.Person
.Include(p => p.PersonType)
.ThenInclude(pt => pt.Type)
.Include(a => a.PersonAddress)
.Where(p => p.Active)
.GroupBy(p => new { item = 1 }); // => THROW EXCEPTION INDEX OUT OF RANGE

I'm using EF 2.0.1 version
Stack

em System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
em Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.BindSubqueryProjectionIndex(Int32 projectionIndex, IQuerySource querySource)
em Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
em System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
em Remotion.Linq.Parsing.ThrowingExpressionVisitor.Visit(Expression expression)
em Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.Visit(Expression expression)
em Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitOrderByClause(OrderByClause orderByClause, QueryModel queryModel, Int32 index)
em Remotion.Linq.Clauses.OrderByClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
em Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection1 bodyClauses, QueryModel queryModel) em Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel) em Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel) em Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel) em Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitSubQuery(SubQueryExpression expression) em Remotion.Linq.Clauses.Expressions.SubQueryExpression.Accept(ExpressionVisitor visitor) em System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) em Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression1 node)
em System.Linq.Expressions.Expression1.Accept(ExpressionVisitor visitor) em System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) em System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes) em System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) em Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMethodCall(MethodCallExpression node) em System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) em System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) em System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node) em System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor) em System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) em Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression1 node)
em System.Linq.Expressions.Expression1.Accept(ExpressionVisitor visitor) em System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) em System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes) em System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) em Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMethodCall(MethodCallExpression node) em System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) em System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) em Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection) em Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.HandleGroup(EntityQueryModelVisitor entityQueryModelVisitor, GroupResultOperator groupResultOperator, QueryModel queryModel) em Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.<>c.<.cctor>b__33_11(EntityQueryModelVisitor v, ResultOperatorBase r, QueryModel q) em Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.HandleResultOperator(EntityQueryModelVisitor entityQueryModelVisitor, ResultOperatorBase resultOperator, QueryModel queryModel) em Microsoft.EntityFrameworkCore.Query.Internal.RelationalResultOperatorHandler.HandlerContext.EvalOnClient(Boolean requiresClientResultOperator) em Microsoft.EntityFrameworkCore.Query.Internal.RelationalResultOperatorHandler.HandleGroup(HandlerContext handlerContext) em Microsoft.EntityFrameworkCore.Query.Internal.RelationalResultOperatorHandler.HandleResultOperator(EntityQueryModelVisitor entityQueryModelVisitor, ResultOperatorBase resultOperator, QueryModel queryModel) em Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, Int32 index) em Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, Int32 index) em Remotion.Linq.QueryModelVisitorBase.VisitResultOperators(ObservableCollection1 resultOperators, QueryModel queryModel)
em Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
em Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
em Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
em Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
em Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](QueryModel queryModel)
--- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada ---
em Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, INodeTypeProvider nodeTypeProvider, IDatabase database, IDiagnosticsLogger1 logger, Type contextType) em Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass15_01.b__0()
em Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler) em Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 compiler)
em Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
em Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
em Remotion.Linq.QueryableBase1.GetEnumerator() em System.Linq.SystemCore_EnumerableDebugView1.get_Items()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

5 participants