c# - netstandard 1.5 中的 BinaryFormatter

标签 c# binaryformatter .net-core-rc2

根据List of .NET CoreFx APIs and their associated .NET Platform Standard version , System.Runtime.Serialization.Formatters 自 1.3 起被添加到 .NET 平台标准中,这很酷,但是当我尝试在 .Net Core RC2 下创建一个针对 netstandard1.5 的 .Net Core 类库时,我不能使用它。

代码很简单,只是打算声明一个BinaryFormatter:

public class Problems {
    private System.Runtime.Serialization.Formatters.Binary.BinaryFormatter _formatter;
}

错误是:

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

这里是 project.json,我没有做任何修改:

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.5.0-rc2-24027",
  },

  "frameworks": {
    "netstandard1.5": {
      "imports": "dnxcore50"
    }
  }
}

那么,我需要依赖另一个包吗?为什么?对于列表中的所有 API,一个 netstandard 名字对象难道还不够吗?

最佳答案

  • System.Runtime.Serialization.Formatters 包是在 RC2 之后添加的,它应该包含在明天的 1.0 版本中。同时,您可以使用 MyGet 中的版本.
  • System.Runtime.Serialization.Formatters 的 1.0 版将不包含 BinaryFormatter。它主要包含序列化属性和接口(interface),以及它们使用的类型。 The full API of that package is here.
  • 即便如此,System.Runtime.Serialization.Formatters 也不会被 NETStandard.Library 引用。如果您想使用它,您需要将它显式添加到您的 project.json 中。
  • BinaryFormatter will be available in a future version of .Net Core.

关于c# - netstandard 1.5 中的 BinaryFormatter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38036864/

相关文章:

c# - 如何更改应用程序的初始屏幕位置?

c# - 无法读取超过流的末尾

zip - 在 dotnet core 中打开和编辑受密码保护的 zip

c# - 如何使用 C# 应用程序在本地保存 cookie?

c# - 如何删除该实例中的类实例

c# - 如何在 SqlDataSource 中使用 appSettings 键

c# - 通过套接字发送大型序列化对象仅在尝试增加字节数组时失败,但在使用大量字节数组时没问题

c# - ASP.NET Core HTTPRequestMessage 返回奇怪的 JSON 消息

visual-studio-2015 - Visual Studio 2015 ASP.NET 核心 RC2 : loss of Custom Item Templates