Skip to content

[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

Description

@jiangzeng01

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

Activity

  1. ghost added
    untriaged
    on Mar 16, 2021
  2. jiangzeng01 commented on Mar 16, 2021

    @jiangzeng01
    ContributorAuthor

    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.

  3. eiriktsarpalis commented on Mar 16, 2021

    @eiriktsarpalis
    Member

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

  4. 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[/+] on Mar 17, 2021
  5. jiangzeng01 commented on Mar 17, 2021

    @jiangzeng01
    ContributorAuthor

    @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
  6. eiriktsarpalis commented on Mar 17, 2021

    @eiriktsarpalis
    Member

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

  7. smitpatel commented on Mar 17, 2021

    @smitpatel
    Contributor

    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.

  8. jiangzeng01 commented on Mar 18, 2021

    @jiangzeng01
    ContributorAuthor

    @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?

  9. eiriktsarpalis commented on Mar 18, 2021

    @eiriktsarpalis
    Member

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

  10. smitpatel commented on Mar 18, 2021

    @smitpatel
    Contributor

    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.

  11. dougbu commented on Mar 18, 2021

    @dougbu
    Contributor

    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.

  12. ghost locked as resolved and limited conversation to collaborators on Apr 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-System.Linquntriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions