2017-03-01 356 views
0

我用EF在Asp.net核心,但在下面的代码获得如下错误:Asp.net核心EF options.UseInMemoryDatabase System.TypeLoadException

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

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

} 

错误消息:

的例外类型'System.TypeLoadException'发生在 Microsoft.EntityFrameworkCore.dll中,但未在用户代码中处理

其他信息:无法加载类型 'Microsoft.Extensions.De pendencyInjection.Extensions.ServiceCollectionExtensions' from assembly'Microsoft.Extensions.DependencyInjection.Abstractions, Version = 1.1.0.0,Culture = neutral,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,
爱德华

回答

2

尝试之后,我改变了“1.0.0-RC2决赛”为“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 
0

我只是想补充一点,我必须在识别包恢复之前重新启动VS2017。在此之前,我得到了一个错误

DbContextOptionsBuilder不包含定义 UseInMemoryDatabase()...

我希望这可以节省您的时间。