我在Asp.net Core中使用了EF,但是在下面的代码中出现了以下错误:
public class TodoContext : DbContext
{
public TodoContext(DbContextOptions<TodoContext> options)
: base(options)
{
}
public DbSet<TodoItem> TodoItems { get; set; }
}
错误讯息:
类型&#39; System.TypeLoadException&#39;的例外情况发生在 Microsoft.EntityFrameworkCore.dll但未在用户代码中处理
其他信息:无法加载类型 &#39; Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions&#39; 来自assembly&#39; Microsoft.Extensions.DependencyInjection.Abstractions, Version = 1.1.0.0,Culture = neutral,PublicKeyToken = adb9793829ddae60&#39;。
这是我的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,
爱德华
答案 0 :(得分:8)
尝试之后,我将“1.0.0-rc2-final”更改为“1.1.0”,我已经尝试了,但我发现有一个警告,“依赖冲突.CoreMVCWebAPI 1.0.0期望Microsoft.EntityFrameworkCore。 InMemory&gt; = 1.1.0但收到了1.0.0-rc2-final“,在手动安装此软件包而不是仅更改project.json之后,它现在可以正常工作。
Install-Package Microsoft.EntityFrameworkCore.InMemory