netstandard 1.5 中的 BinaryFormatter

BinaryFormatter in netstandard 1.5

根据 List of .NET CoreFx APIs and their associated .NET Platform Standard version,System.Runtime.Serialization.Formatters 从 1.3 开始就被添加到 .NET 平台标准中,这很酷,但是当我尝试创建 .Net Core 时 class以 netstandard1.5 under.Net Core RC2 为目标的库,我无法使用它。

代码很简单,只是打算声明一个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 绰号不应该足够了吗?

您在 RC2 中找不到 BinaryFormatter

http://packagesearch.azurewebsites.net/

关于是否会成为.NET Core的一部分,可以参考这个pull request,

https://github.com/dotnet/corefx/pull/8302/files

我猜它会成为 .NET Core 1.0 RTM 或 1.1 版本的一部分。

  • System.Runtime.Serialization.Formatters包是在RC2之后添加的,应该会包含在明天的1.0版本中。同时,您可以使用 MyGet.
  • 中的版本
  • System.Runtime.Serialization.Formatters 的 1.0 版本将不包含 BinaryFormatter。它主要包含序列化属性和接口,以及它们使用的类型。 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.