8

Currently I am trying to develop a C# (ASP.NET MVC) web application on a macOS, I am running on .NET 6.0.402

When I run dotnet ef update database to update my database I get this error:

Method not found: 'System.Collections.Generic.IList`1<Microsoft.EntityFrameworkCore.Metadata.Conventions.IModelFinalizingConvention> Microsoft.EntityFrameworkCore.Metadata.Conventions.ConventionSet.get_ModelFinalizingConventions()'.

I did fiddle with my Migrations-> [serial]_[name].designer.cs file since it did not auto-generate the information to match the model I had when I ran dotnet ef migrations add.

Jokes.cs (Model)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace JokeWebApp.Models
{
    public class Joke
    {
        public int Id { get; set; }
        public string? JokeQuestion { get; set; }
        public string? JokeAnswer { get; set; }

        //ctor shortcut for constructor
         public Joke()
        {

        }
    }

}

20221109024428_initialsetup.Designer.cs (Data->Migrations)

// <auto-generated />
using System;
using JokeWebApp.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;


namespace JokeWebApp.Data.Migrations
{
    [DbContext(typeof(ApplicationDbContext))]
    [Migration("20221109024428_initialsetup")]
    partial class initialsetup
    {
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
#pragma warning disable 612, 618


modelBuilder.HasAnnotation("ProductVersion", "6.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

modelBuilder.Entity("JokeWebApp.Models.Joke", b =>
{
b.Property<int>("Id").ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

b.Property<string>("JokeAnswer")
.HasColumnType("nvarchar(max)");

b.Property<string>("JokeQuestion")
.HasColumnType("nvarchar(max)");

b.HasKey("Id");

b.ToTable("Joke");
});

...

Project.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UserSecretsId>aspnet-JokeWebApp-c27aee20-1e9d-4266-993b-368018ae336f</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <None Update="app.db" CopyToOutputDirectory="PreserveNewest" ExcludeFromSingleFile="true" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.10" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.10" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.10" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.10" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.10" />
  </ItemGroup>

</Project>

I am not sure if I am missing a required package or I messed up somewhere in my fiddling of the designer.cs file.

Can somebody point me in the right direction?

I made sure the package references in my Project.csproj were up to date. Wondering if there may be some discrepency with:

 <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />

The other packages has a version of "6.0.10", not sure if I should put that for the version for the Microsoft.EntityFrameworkCore.SqlServer.SqlServer since it was a package I downloaded in order to have access to SqlServerValueGenerationStrategy.IdentityColumn .

I also read on another thread the issue may be due to an old version of DLL. How do I make sure that everything is the latest files, what are the built items I need to delete before I can rebuild the application?

mleng
  • 81
  • 1
  • 2

5 Answers5

7

There are version mismatches between nuget packages.Upgrade the ef core packages to version 7.0.0 and your problem will be solved.

Hasan Avcı
  • 71
  • 1
  • 2
2

my solution went add in .net core 7:

Microsoft.EntityFrameworkCore.InMemory Version="7.0.4"

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 20 '23 at 21:44
0

The NuGet version 7.0.0 onwards of EntityFrameworkCore, only works if you have the NET 7.0 version installed, so in your case you must update again to 6.0.13, which is the latest version to date. I had the same problem so I hope you were able to finally fix it by installing NET 7.0 or going back to the old references.

SrTemas
  • 19
  • 4
0

the problem in my case was that am using efcore 7.0 while working on a .Net 6 project. downgrading the efcore to match the .Net framework solved it.

Pope Francis
  • 557
  • 8
  • 9
0

If your app uses ASP.NET Core Health Checks with the in-memory storage provider, that can pull in a dependency on an older version of EntityFrameworkCore than the one the app uses for its main database connection.

DGreen
  • 1,027
  • 1
  • 8
  • 17