【问题标题】:How do I include 'System.Runtime.Serialization.Json' namespace in my VSCode project on Mac OS X?如何在 Mac OS X 上的 VSCode 项目中包含“System.Runtime.Serialization.Json”命名空间?
【发布时间】:2015-06-10 19:56:43
【问题描述】:

我希望在我的 Mac OS X 上的一个简单的 Visual Studio Code 控制台应用程序中使用 System.Runtime.Serialization.Json,但我遇到了这个编译错误:

The type or namespace name 'Json' does not exist in the namespace 'System.Runtime.Serialization' (are you missing an assembly reference?)

根据这篇文章 - Where is the System.Runtime.Serialization.Json namespace?,我将 "System.ServiceModel.Web": "1.0.0" 添加到我的 project.json 文件中,但这并没有帮助。我添加了 1.0.0,因为这是我在 nuget 中找到的唯一版本 - https://www.nuget.org/packages/System.ServiceModel.Web/

作为替代方案,我尝试通过在我的 project.json 中添加以下内容来使用 https://www.nuget.org/packages/Newtonsoft.Json/6.0.8 - "Newtonsoft.Json": "6.0.8" 但然后再次添加 using Newtonsoft.Json; 的引用会导致编译错误 - The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

最终我想从我的 VSCode 控制台应用程序中反序列化一个 json 流,因此希望获得有关如何完成此操作的指针?

【问题讨论】:

标签: c# json macos asp.net-core visual-studio-code


【解决方案1】:

System.Runtime.Serialization.Json 不会被移植到 .Net Core;转至Newtonsoft.Json,您做了正确的事。

很遗憾,您仅将其添加到 dnxcore50 部分;您需要将其添加到与框架无关的依赖部分:

{
  "version": "1.0.0-*",
  "dependencies": {
    "System.ServiceModel.Web": "1.0.0",
    "Newtonsoft.Json": "6.0.8"
  },
  "commands": {
    "run": "run"
  },
  "frameworks": {
    "dnx451": {},
    "dnxcore50": {
      "dependencies": {
        "System.Console": "4.0.0-beta-*",
        "System.ServiceModel.Web": "1.0.0"
      }
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    相关资源
    最近更新 更多