Skip to content

Cannot Add migration in .net 8 and EF Core 6 #164

@blfuentes

Description

@blfuentes

Using .net 8 and EF Core 6.0.7
Part of my Program.fs

    [<EntryPoint>]
    let main args =
        Dapper.FSharp.MSSQL.OptionTypes.register()

        let builder = WebApplication.CreateBuilder(args)
        builder.WebHost
            .ConfigureAppConfiguration(fun builderContext config -> 
                            config.AddJsonFile(sprintf "appsettings.%s.json" builderContext.HostingEnvironment.EnvironmentName, optional = false, reloadOnChange = true)
                            config.AddUserSecrets()
                            config.AddEnvironmentVariables()
                            |> ignore)

        builder.Services
            .AddDbContext<ApplicationDbContext.ApplicationDbContext>(fun options -> 
                options
                    .UseSqlite("Data Source=./Data/Identity.db") |> ignore)

My ApplicationDbContext:

module ApplicationDbContext =

    open Microsoft.AspNetCore.Identity
    open Microsoft.AspNetCore.Identity.EntityFrameworkCore
    open Microsoft.EntityFrameworkCore
    open Microsoft.EntityFrameworkCore.Sqlite
    open Microsoft.EntityFrameworkCore.Design

    type ApplicationDbContext(options : DbContextOptions<ApplicationDbContext>) = 
        inherit IdentityDbContext(options)

        // OPTIONAL. seed the database with some initial roles. 
        override __.OnModelCreating (modelBuilder : ModelBuilder) =
            base.OnModelCreating(modelBuilder)
            modelBuilder.Entity<IdentityRole>().HasData(
                [|
                    IdentityRole(Name = "admin", NormalizedName = "ADMIN")
                    IdentityRole(Name = "user", NormalizedName = "USER")
                |]) |> ignore

    type ApplicationDbContextFactory() =
        interface IDesignTimeDbContextFactory<ApplicationDbContext> with
            member __.CreateDbContext (args: string[]) =
                let optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>()
                optionsBuilder.UseSqlite("Data Source=./Data/Identity.db") |> ignore
                new ApplicationDbContext(optionsBuilder.Options)

And my nuget packages:

<Project>
	<PropertyGroup>
		<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
	</PropertyGroup>
	<ItemGroup>
		<PackageVersion Include="Dapper" Version="2.1.35" />
		<PackageVersion Include="Dapper.FSharp" Version="4.9.0" />
		<PackageVersion Include="EntityFrameworkCore.FSharp" Version="6.0.7" />
		<PackageVersion Include="FSharp.Core" Version="8.0.401" />
		<PackageVersion Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
		<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.10" />
		<PackageVersion Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.10" />
		<PackageVersion Include="Microsoft.Data.Sqlite" Version="8.0.10" />
		<PackageVersion Include="Microsoft.Data.Sqlite.Core" Version="8.0.10" />
		<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
		<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10" />
		<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
		<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
			<PrivateAssets>all</PrivateAssets>
		</PackageVersion>
		<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
		<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
		<PackageVersion Include="System.Data.SqlClient" Version="4.8.6" />
	</ItemGroup>
</Project>

And get this error when I try to add a migration:

System.MissingMethodException: Method not found: 'System.String Microsoft.EntityFrameworkCore.Design.ICSharpHelper.Fragment(Microsoft.EntityFrameworkCore.Design.MethodCallCodeFragment, System.String, Boolean)'.
at EntityFrameworkCore.FSharp.EFCoreFSharpServices.Microsoft.EntityFrameworkCore.Design.IDesignTimeServices.ConfigureDesignTimeServices(IServiceCollection services)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureDesignTimeServices(Type designTimeServicesType, IServiceCollection services)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureReferencedServices(IServiceCollection services, String provider)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.CreateServiceCollection(DbContext context)
at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(DbContext context)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Method not found: 'System.String Microsoft.EntityFrameworkCore.Design.ICSharpHelper.Fragment(Microsoft.EntityFrameworkCore.Design.MethodCallCodeFragment, System.String, Boolean)'.

Link to repo
https://github.com/blfuentes/SleepTracker/tree/identity-implementation

Tried following the steps here and same issue...
https://github.com/efcore/EFCore.FSharp/blob/master/GETTING_STARTED.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions