Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BinaryFormatter in netstandard 1.5

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?

like image 467
Jaren Duan Avatar asked Mar 11 '23 21:03

Jaren Duan


2 Answers

  • 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.
like image 157
svick Avatar answered Mar 19 '23 14:03

svick


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.

like image 39
Lex Li Avatar answered Mar 19 '23 16:03

Lex Li