Skip to content

EF Core 10 throws System.DivideByZeroException if number of parameters are between 2070 and 2100 #37151

@ksusac

Description

@ksusac

Bug description

As stated in title, if number of parameters are between 2070 and 2100, EF throws DivideByZeroException.

Your code

using Microsoft.EntityFrameworkCore;

List<int> list = [];

for (int i = 0; i < 2097; i++)
{
    list.Add(i);
}

using var dbContext = new BloggingContext();

var blogs = await dbContext.Set<Blog>()
    .Where(b => list.Contains(b.BlogId))
    .ToListAsync();

class BloggingContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=EFCore10Demo;Trusted_Connection=True;");
    public DbSet<Blog> Blogs { get; set; }
}

public class Blog
{
    public int BlogId { get; set; }
    public string? Url { get; set; }
}

Stack traces

System.DivideByZeroException:
   at Microsoft.EntityFrameworkCore.Query.SqlNullabilityProcessor+<>c__DisplayClass33_0.<VisitIn>g__ProcessInExpressionValues|1 (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.Query.SqlNullabilityProcessor.VisitIn (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlNullabilityProcessor.VisitIn (Microsoft.EntityFrameworkCore.SqlServer, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.Query.SqlNullabilityProcessor.Visit (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.Query.SqlNullabilityProcessor.Visit (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.Query.SqlNullabilityProcessor.Visit (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.Query.SqlNullabilityProcessor.VisitExtension (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlNullabilityProcessor.VisitExtension (Microsoft.EntityFrameworkCore.SqlServer, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.Query.SqlNullabilityProcessor.Process (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlNullabilityProcessor.Process (Microsoft.EntityFrameworkCore.SqlServer, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerParameterBasedSqlProcessor.ProcessSqlNullability (Microsoft.EntityFrameworkCore.SqlServer, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.Query.RelationalParameterBasedSqlProcessor.Process (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerParameterBasedSqlProcessor.Process (Microsoft.EntityFrameworkCore.SqlServer, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.Query.RelationalParameterBasedSqlProcessor.Process (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalCommandCache.GetRelationalCommandTemplate (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.Internal.RelationalCommandResolverExtensions.RentAndPopulateRelationalCommand (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1+AsyncEnumerator+<InitializeReaderAsync>d__21.MoveNext (Microsoft.EntityFrameworkCore.Relational, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)

Verbose output


EF Core version

10.0

Database provider

No response

Target framework

.NET 10

Operating system

No response

IDE

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions