Search code examples
azure-devopsentity-framework-6.net-6.0

Azure DevOps build fails after updating to .NET/EF Core 6, ModelShapShot with long (64bit int) id fails


I'm getting a very strange issue with Azure DevOps after updating my ASP.NET from 5 to 6, which uses entity framework and SQL server. My build pipeline is set to use .NET 6.0.x, and the windows-2022 agent from the pool. My EF Core dlls are 6.0.2.

The project builds fine locally, but with the .NET build task on Azure devops, I get compilation errors. It complains about the 'AppDbContextModelSnapshot.cs' file. It seems going from .NET5 to 6 has added these lines to this file, going from this:

b.Property<long>("Id")
     .ValueGeneratedOnAdd()
     .HasColumnType("bigint")
     .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

To this:

b.Property<long>("Id")
   .ValueGeneratedOnAdd()
   .HasColumnType("bigint");

SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"), 1L, 1);

Note: the type for the PK of the entity is a 'long'.

This builds runs locally, migrates fine locally, but on deployment to Azure DevOps for a build, produces these exceptions:

Data\Application\Migrations\AppDbContextModelSnapshot.cs(24,78): Error CS1503: Argument 2: cannot convert from 'long' to 'int'

I can manually edit the generated code to remove the arguements, but why is it complaining? I can't see anything wrong with the code locally, and cannot see where this conversion is coming from. It seems fine based on what intellisense is telling me:

Use identity column

Why is there this difference on Azure DevOps?


Solution

  • It turned out in my csproj file there where two references to the EF Core library, one to an older version. Must have been a bad merge at some point.