BinaryFormatter in netstandard 1.5

笑着哭i 提交于 2019-12-21 18:03:59

问题


According to the List of .NET CoreFx APIs and their associated .NET Platform Standard version, System.Runtime.Serialization.Formatters is added into to the .NET Platform Standard since 1.3, which is cool, but when I try to create a .Net Core class library targeting netstandard1.5 under.Net Core RC2, I can't use it.

The code is simple, just intending to declare a BinaryFormatter:

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

Error is :

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

Here is the project.json, which I did no modifications:

{
  "version": "1.0.0-*",

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

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

So, is there another package that I need depend on? And Why? Shouldn't a netstandard moniker be enough for all the APIs in the list?


回答1:


  • The System.Runtime.Serialization.Formatters package was added after RC2, it should be included in the 1.0 release tomorrow. In the meantime, you can use a version from MyGet.
  • The 1.0 version of System.Runtime.Serialization.Formatters will not contain BinaryFormatter. It mostly contains serialization attributes and interfaces, and types used by them. The full API of that package is here.
  • Even then, System.Runtime.Serialization.Formatters is not referenced by NETStandard.Library. If you want to use it, you will need to explicitly add it to your project.json.
  • BinaryFormatter will be available in a future version of .Net Core.



回答2:


You cannot find BinaryFormatter in RC2,

http://packagesearch.azurewebsites.net/

About whether it would be part of .NET Core, you can refer to this pull request,

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

I guess it would be part of .NET Core 1.0 RTM, or 1.1 release.



来源:https://stackoverflow.com/questions/38036864/binaryformatter-in-netstandard-1-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!