Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2017 .NET Core BinaryFormatter

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
like image 568
Alois Kraus Avatar asked Mar 09 '17 19:03

Alois Kraus


People also ask

Why is BinaryFormatter obsolete?

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.

Why is BinaryFormatter insecure?

BinaryFormatter uses violates 2.), which is a huge security risk because it makes possible to run any code.

What is BinaryFormatter in c#?

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.

Is string Serializable in C#?

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.


1 Answers

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

like image 172
johnny 5 Avatar answered Sep 19 '22 14:09

johnny 5