Asp.net Core EF options.UseInMemoryDatabase System.TypeLoadException

2024-02-03

我在 Asp.net Core 中使用 EF,但在以下代码中出现以下错误:

public class TodoContext : DbContext
{
    public TodoContext(DbContextOptions<TodoContext> options)
        : base(options)
    {

    }
    public DbSet<TodoItem> TodoItems { get; set; }

}

错误信息:

发生“System.TypeLoadException”类型的异常 Microsoft.EntityFrameworkCore.dll 但未在用户代码中处理

附加信息:无法加载类型 'Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions' 来自程序集“Microsoft.Extensions.DependencyInjection.Abstractions”, 版本=1.1.0.0,文化=中性,PublicKeyToken=adb9793829ddae60'。

这是我的 Project.json

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",

    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    //Dependence for MVC
    "Microsoft.AspNetCore.Mvc": "1.1.1",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    //Dependence for EF
    "Microsoft.EntityFrameworkCore": "1.1.0",
    "Microsoft.EntityFrameworkCore.InMemory": "1.0.0-rc2-final"
    //Dependence for EF with SQL, this is avalible under VS 2017 RC
    //"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    //Entity Framework commands to maintain the database
    //"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview4-final"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    //used for Razor pages which are compiled at runtime,and the compiler needs access to reference assemblies,
    //to make sure it compiles correctly
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

任何帮助,将不胜感激。
Reards,
爱德华


经过尝试,我将“1.0.0-rc2-final”更改为“1.1.0”,我已经尝试过,但我发现有一个警告,“依赖项冲突。CoreMVCWebAPI 1.0.0预期 Microsoft.EntityFrameworkCore.InMemory >= 1.1.0 但收到 1.0.0-rc2-final",手动安装此包而不是仅更改 project.json 后,它现在可以工作了。

Install-Package Microsoft.EntityFrameworkCore.InMemory
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Asp.net Core EF options.UseInMemoryDatabase System.TypeLoadException 的相关文章

随机推荐