根据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/