我做了以下事情:
- 创建了一个新的 Web.Api 项目:“WFW3”。我在ASP.Net 5下使用了“Web API”模板。
- 我再次使用ASP.Net 5创建了一个新的类库“Foo.Domain” 。
- 我从 API 项目中添加了对它的引用。
- 我将来自 Nuget 的Neo4j.Driver(一个可移植类库)安装到 Foo.Domain 项目中。Neo4j-NuGet
到目前为止,一切似乎都很好。一切都编译了,尽管它什么也没做。
在 Foo.Domain 中,我创建了一个类,该类的方法在“使用”语句中引用了 GraphDatabase 类。这就是它坏的地方。
我收到此错误消息(以及其他类似的消息):
'IDisposable' 类型是在未引用的程序集中定义的。您必须添加对程序集“System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”的引用。Foo.Domain..NET Framework 4.5.1 C:\dev\WFW3\src\Foo.Domain\FooRepository.cs
我的理解是绑定重定向在 ASP.Net 5 中不可用。这是正确的吗?如果没有引用正确版本的 System.Runtime,如何解决这个问题?System.Runtime中的项目可供我使用。它似乎正在从 Neo4j.Driver.V1 程序集中寻找旧版本的 System.Runtime。我尝试了此处找到的解决方案(内森的回答),但随后它开始抱怨我试图导入两种不同类型的运行时库,我需要删除一个。但是我应该删除哪个,以及如何删除?
API 项目.json
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Foo.Domain": "1.0.0-*",
"Microsoft.ApplicationInsights.AspNet": "1.0.0-rc1",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
Foo.Domain 项目.json
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Foo.Domain": "1.0.0-*",
"Microsoft.ApplicationInsights.AspNet": "1.0.0-rc1",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
FooRepository 代码(在 Foo.Domain 中):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Neo4j.Driver.V1;
namespace Foo.Domain
{
public class FooRepository: IFooRepository
{
public Foo GetById(string Id)
{
// The next lines inside the 'using' are getting the error.
using (var driver = GraphDatabase.Driver("http://localhost:7474/"))
using (var session = driver.Session())
{
var result = session.Run("CREATE (n) RETURN n");
}
return null;
}
}
}