Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve Method not found: System.Collections.Generic.IList`1<Microsoft.EntityFrameworkCore.Metadata.Conventions.IModelFinalizingConvention>

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?

like image 400
mleng Avatar asked Dec 03 '25 17:12

mleng


2 Answers

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

like image 99
Hasan Avcı Avatar answered Dec 06 '25 06:12

Hasan Avcı


my solution went add in .net core 7:

Microsoft.EntityFrameworkCore.InMemory Version="7.0.4"

like image 29
walaks Silva Avatar answered Dec 06 '25 08:12

walaks Silva