gpt4 book ai didi

neo4j - 解析 ASP.Net 5 中的引用, "IDisposable is ... not referenced"

转载 作者:行者123 更新时间:2023-12-04 15:19:58 26 4
gpt4 key购买 nike

我做了以下事情:

  • 创建了一个新的 Web.Api 项目:“WFW3”。我使用了“Web API”模板
    下ASP.Net 5 .
  • 我再次使用 创建了一个新的类库“Foo.Domain” ASP.NET
    5
    .
  • 我从 API 项目中添加了对它的引用。
  • 我安装了 Neo4j.驱动程序 (一个可移植的类库)从 Nuget 到 Foo.Domain 项目。 Neo4j-NuGet

  • 到目前为止,一切似乎都很好。一切都编译了,尽管它什么也没做。

    在 Foo.Domain 中,我创建了一个类,该类的方法在“使用”语句中引用了 GraphDatabase 类。这就是它坏的地方。

    我收到此错误消息(以及其他类似的消息):

    The type 'IDisposable' is defined in an assembly that is not referenced. You must add a reference to assembly '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



    我的理解是绑定(bind)重定向在 ASP.Net 5 中不可用。这是正确的吗?如果没有引用正确版本的 System.Runtime,如何解决这个问题?
    System.Runtime 中的项目可供我使用。它似乎正在从 Neo4j.Driver.V1 程序集中寻找旧版本的 System.Runtime。我尝试了此处找到的解决方案 ( Nathan's answer),但随后它开始提示我试图导入两种不同类型的运行时库,我需要删除一个。但是我应该删除哪个,以及如何删除?

    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;
    }
    }
    }

    最佳答案

    引用这个类似的问题:What do I do when ASP.NET 5 (vNext) can't redirect bindings?

    该问题中的问题似乎与 dnxcore50 的事实有关。框架包含在项目中。

    "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
    }

    并删除它解决了这个问题。
    "frameworks": {
    "dnx451": { }
    }

    这适用于他们的情况,也应该适用于您。我相信您之所以会得到这个,是因为省略了此处引用的 Core CLR (dnxcore50) 框架所需的依赖项:

    Frameworks

    This snippet will build for Desktop (dnx451) or Core CLR (dnxcore50). Core CLR has many extra dependencies as the packages that make up the BCL need to be referenced...


    {
    "frameworks": {
    "dnx451": {},
    "dnxcore50": {
    "dependencies": {
    "System.Collections": "4.0.0.0",
    "System.Collections.Concurrent": "4.0.0.0",
    "System.ComponentModel": "4.0.0.0",
    "System.Linq": "4.0.0.0",
    "System.Reflection": "4.0.10.0",
    "System.Runtime": "4.0.20.0",
    "System.Runtime.InteropServices": "4.0.10.0",
    "System.Threading": "4.0.0.0",
    "System.Threading.Tasks": "4.0.0.0"
    }
    }
    }
    }

    这就是为什么当它从上一个问题中删除时,该项目起作用了。我看到的与此问题相关的大多数其他帖子也建议删除 dnxcore50

    你也可以看看这个以获得更好的理解......

    Framework-specific dependencies

    You can also add dependencies for a particular framework like this:


    {
    "frameworks": {
    "dnxcore50":{
    "dependencies":{
    "System.Runtime": "4.0.0.0"
    }
    },
    "dnx451":{}
    }
    }

    In the above example, the System.Runtime dependency is only needed for the dnxcore50 target, not dnx451. It is often the case that you will have extra dependencies on Core CLR, because there are packages that you need to depend on in Core CLR that are part of .NET 4.5.x.



    备注

    While it is technically true that you do not need the System.Runtime package on .NET 4.5.1, it also doesn’t matter if you add it as a top level dependency. Each of the System.* packages will work as a top level dependency. So, you don’t always have to have this separation. You could add System.Runtime as a top level dependency and it will not impact your application when on .NET 4.5.1.



    附加引用资料:

    Diagnosing dependency issues with ASP.NET 5

    How can I diagnose missing dependencies (or other loader failures) in dnx?

    关于neo4j - 解析 ASP.Net 5 中的引用, "IDisposable is ... not referenced",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36974305/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com