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

[6.0.100-preview.3.21165.6] 3.1/5 apps can't fetch data with EfCore5 and earlier versions when run against 6.0 #49683

Closed
jiangzeng01 opened this issue Mar 16, 2021 · 10 comments
Assignees
Labels
area-System.Linq untriaged New issue has not been triaged by the area owner

Comments

@jiangzeng01
Copy link
Contributor

Application Name: Apps that use EntityFrameWorkCore
OS: Windows 10 RS5
CPU: X64
.NET Build Number: 6.0.100-preview.3.21165.6 (master branch)

Verify Scenarios:
1). Windows 10 RS5 X64 + .NET Core SDK build 6.0.100-preview.3.21165.6: Fail
2). Windows 10 RS5 X64 + .NET Core SDK build 6.0.100-preview.2.21158.2: Pass
3). Windows 10 RS5 X64 + .NET Core SDK build 5.0.104 : Pass
4). Windows 10 RS5 X64 + .NET Core SDK build 3.1.300 Pass

Source Code & Repro steps check at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1293031

Expected Result:
Display record count in database table

Actual Result:

The type initializer for 'Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor' threw an exception.
***************************
   at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.Expand(Expression query)
   at Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(Expression query)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryTranslationPreprocessor.Process(Expression query)
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Collections.Generic.IEnumerable<TEntity>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at ConsoleApp1.Program.Main(String[] args) in C:\Users\appcompat\source\repos\ConsoleApp3\ConsoleApp1\Program.cs:line 18
***************************
System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception.
 ---> System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethods..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.EntityFrameworkCore.Query.QueryableMethods.get_FirstWithPredicate()
   at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor..cctor()

Sample Code to Repro :

static void Main(string[] args)

{
{
try
{
using (var context = new EFCoreDemoContext())
{
Console.WriteLine(context.Persons.ToList().Count); //fail here
}
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
}
public class EFCoreDemoContext : DbContext
{
public DbSet<Person> Persons { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=(localdb)\MSSQLLocalDB;Database=TestDB;Trusted_Connection=True;MultipleActiveResultSets=true");
}
}
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}

Findings:
System.Linq.dll
System.Linq.Queryable.dll causes this issue.

@dotnet-actwx-bot @dotnet/compat

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Mar 16, 2021
@ghost
Copy link

ghost commented Mar 16, 2021

Tagging subscribers to this area: @eiriktsarpalis
See info in area-owners.md if you want to be subscribed.

Issue Details

Application Name: Apps that use EntityFrameWorkCore
OS: Windows 10 RS5
CPU: X64
.NET Build Number: 6.0.100-preview.3.21165.6 (master branch)

Verify Scenarios:
1). Windows 10 RS5 X64 + .NET Core SDK build 6.0.100-preview.3.21165.6: Fail
2). Windows 10 RS5 X64 + .NET Core SDK build 6.0.100-preview.2.21158.2: Pass
3). Windows 10 RS5 X64 + .NET Core SDK build 5.0.104 : Pass
4). Windows 10 RS5 X64 + .NET Core SDK build 3.1.300 Pass

Source Code & Repro steps check at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1293031

Expected Result:
Display record count in database table

Actual Result:

The type initializer for 'Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor' threw an exception.
***************************
   at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.Expand(Expression query)
   at Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(Expression query)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryTranslationPreprocessor.Process(Expression query)
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Collections.Generic.IEnumerable<TEntity>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at ConsoleApp1.Program.Main(String[] args) in C:\Users\appcompat\source\repos\ConsoleApp3\ConsoleApp1\Program.cs:line 18
***************************
System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception.
 ---> System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethods..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.EntityFrameworkCore.Query.QueryableMethods.get_FirstWithPredicate()
   at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor..cctor()

Sample Code to Repro :

static void Main(string[] args)

{
{
try
{
using (var context = new EFCoreDemoContext())
{
Console.WriteLine(context.Persons.ToList().Count); //fail here
}
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
}
public class EFCoreDemoContext : DbContext
{
public DbSet<Person> Persons { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=(localdb)\MSSQLLocalDB;Database=TestDB;Trusted_Connection=True;MultipleActiveResultSets=true");
}
}
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}

Findings:
System.Linq.dll
System.Linq.Queryable.dll causes this issue.

@dotnet-actwx-bot @dotnet/compat

Author: jiangzeng01
Assignees: ericstj, layomia
Labels:

area-System.Linq

Milestone: -

@jiangzeng01
Copy link
Contributor Author

jiangzeng01 commented Mar 16, 2021

This issue fails 60+ app in our lab as it is a common functionality break that is used very frequently by apps.
Could you please help to take a look as soon? @ericstj Please let me know if I assign to a wrong person.

@eiriktsarpalis
Copy link
Member

This might be related to dotnet/efcore#24002. EF have released a fixed which has been backported to earlier releases as well.

@eiriktsarpalis eiriktsarpalis self-assigned this Mar 16, 2021
@jiangzeng01 jiangzeng01 changed the title [6.0.100-preview.3.21165.6] EntityFramework can't fetch data with 6.0.0-preview.3.21163.9 NetCore runtime [6.0.100-preview.3.21165.6] 3.1/5 apps can't fetch data with EfCore5 and earlier versions when run against 6.0 Mar 17, 2021
@jiangzeng01
Copy link
Contributor Author

jiangzeng01 commented Mar 17, 2021

@eiriktsarpalis Add more information about this issue:

  1. Source code we provided is targeting 3.1 and has dependency to EFCore 5.0.4, it fails when we run against 6.0 (this is what this issue about)
  2. .net6 apps + Efcore6 => PASS

@eiriktsarpalis
Copy link
Member

Tagging @smitpatel who might know what version of EFCore 5 will incorporate the fix.

@smitpatel
Copy link
Member

The EF Core version with the fix included

  • 3.1.14
  • 5.0.5
  • 6.0-preview2

Above are not released yet, fix is already available in nightly builds.

@jiangzeng01
Copy link
Contributor Author

jiangzeng01 commented Mar 18, 2021

@smitpatel Thanks! Is there any way that we can verify with the nightly builds of version 3.1.14 & 5.0.5? Or we need to wait until the release? We want to try the package with the fix.
There might be a lot of existing apps which are using old version of EF Core will fail to run against .NET 6 Preview 3, unless they upgrade the EF Core package version and rebuild their apps. Is there a break change document about this?

@eiriktsarpalis
Copy link
Member

I'm going to close this issue since there is nothing actionable from the libraries perspective.

@smitpatel
Copy link
Member

To reply to @jiangzeng01 - tagging @dotnet/aspnet-build team for nightlies of the patch branches if they exist somewhere.
.NET 6 preview 3 is not public yet. By the time it is released to public associated EF Core packages will be also released so existing apps won't be stuck.

@dougbu
Copy link
Member

dougbu commented Mar 18, 2021

nightlies of the patch branches if they exist somewhere

3.1.14 and 5.0.5 builds all produce shipping packages with identical names. Feeds can't be updated in place; so every build pushes to a unique feed. Recent feeds produced include the following

Those are for the most recent builds that published to public feeds. As long as the entire EF fix is now checked into GitHub (@smitpatel❔), you should be good to go with either @jiangzeng01.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Linq untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

6 participants