Repository navigation
Description
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
jiangzeng01 commentedon 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 commentedon Mar 16, 2021
This might be related to dotnet/efcore#24002. EF have released a fixed which has been backported to earlier releases as well.
[-][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[/+]jiangzeng01 commentedon Mar 17, 2021
@eiriktsarpalis Add more information about this issue:
eiriktsarpalis commentedon Mar 17, 2021
Tagging @smitpatel who might know what version of EFCore 5 will incorporate the fix.
smitpatel commentedon Mar 17, 2021
The EF Core version with the fix included
Above are not released yet, fix is already available in nightly builds.
jiangzeng01 commentedon 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 commentedon Mar 18, 2021
I'm going to close this issue since there is nothing actionable from the libraries perspective.
smitpatel commentedon Mar 18, 2021
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 commentedon Mar 18, 2021
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.