Is with VS 2017 released in the .NET Core tools BinaryFormatter included? When I create a .NET Core console application I cannot find BinaryFormatter. There are many Nuget packages but which one is the right one to get a working BinaryFormatter with .NET Core?
By the way it is a bit awkward to create with a released Visual Studio a project which does not compile. I need to start a cmd shell where my .NET Core console application resides and do a
dotnet restore
to get it to compile. Did I miss a VS command in the references menu?
Edit1
Using Install-Package BinaryFormatter
gives me an exception
PM> Install-Package BinaryFormatter
Restoring packages for d:\source\vc17\NetCoreApp\ConsoleApp1\ConsoleApp2\ConsoleApp2.csproj...
Install-Package : Package BinaryFormatter 1.0.2 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package BinaryFormatter 1.0.2 supports:
- dnx451 (DNX,Version=v4.5.1)
- dnxcore50 (DNXCore,Version=v5.0)
At line:1 char:1
+ Install-Package BinaryFormatter
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Install-Package : One or more packages are incompatible with .NETCoreApp,Version=v1.1.
At line:1 char:1
+ Install-Package BinaryFormatter
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Install-Package : Package restore failed. Rolling back package changes for 'ConsoleApp2'.
At line:1 char:1
+ Install-Package BinaryFormatter
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Due to security vulnerabilities in BinaryFormatter, the following methods are now obsolete and produce a compile-time warning with ID SYSLIB0011 . Additionally, in ASP.NET Core 5.0 and later apps, they will throw a NotSupportedException, unless the web app has re-enabled BinaryFormatter functionality.
BinaryFormatter uses violates 2.), which is a huge security risk because it makes possible to run any code.
BinaryFormatter is used for serialization. It helps you to map a C# object to a binary representation which you can write to a file, a network stream etc. But BinaryWriter does not help you map the C# object to binary data.
But then I researched and found that "string is serializable by default" is only true in . NET framework because string definition is decorated with the Serializable attribute in . NET; whereas, in . NET Core string definition is not decorated with the Serializable attribute.
EDIT
Thanks to @ClockEndGooner for pointing out, that People who are using .Net-Core 2.1 or later there is a Binary Formatter Located in:
System.Runtime.Serialization.Formatters.Binary
Here is a nuget package for that it says it supports core as well:
Install-Package BinaryFormatter
I'm not sure if this contains what you need but is also the System.Runtime.Serialization.Formatters
Install-Package System.Runtime.Serialization.Formatters
These packages work with .Net-Core 1.0 in order for them to work with a 1.1 enviroment you will require cross comiplation you can reference this Core Issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With