The portable class library does not have DataContract or Serialization functions since .NET 4.6

I just released a new copy of Visual Studio 2015 on a completely new copy of Windows 10. I tried to create a simple Portable Class Library Library (PCL) and tried to add a simple data contract:

namespace ClassLibrary1 { using System.Runtime.Serialization; [DataContract] public class Class1 { } } 

And the compiler tells me:

It is not possible to find the name of the type or namespace of the DataContract (if you did not specify the using directive or the assembly reference. The System.Runtime.Serialization namespace appears when there is .NET 4.6 selected as the target.

Serialization seems to be unavailable if .NET Framework 4.6 is selected for targets. If I go back to .NET 4.5.1, then the same code compiles (and works in a more complex project). What is going on here? .NET 4.6 is not ready for Prime Time in Visual Studio? Anyone else come across this?

+4
source share
1 answer

Here was the same problem, and it seems that the solution is to add the appropriate NuGet packages (s) to the project, which contains the functionality that was ported from Core. In particular, you will need serialization primitives , but I included the project.json file below, probably closer to what you want in terms of the actual configuration (dependencies, etc.).

This site also has a β€œsearch engine” for .NET 5 packages, which is basically what you are doing here.

 { "supports": { "net46.app": {}, "uwp.10.0.app": {}, "dnxcore50.app": {} }, "dependencies": { "Microsoft.NETCore": "5.0.0", "Microsoft.NETCore.Portable.Compatibility": "1.0.0", "System.Collections": "4.0.10", "System.Collections.Specialized": "4.0.0", "System.Linq": "4.0.0", "System.Linq.Expressions": "4.0.10", "System.Linq.Queryable": "4.0.0", "System.Net.Requests": "4.0.10", "System.Runtime": "4.0.20", "System.Runtime.Serialization.Primitives": "4.0.10", "System.Runtime.Serialization.Json": "4.0.0", "System.Runtime.Serialization.Xml": "4.0.10" }, "frameworks": { "dotnet": { "imports": "portable-net452+win81" } } } 
+6
source

All Articles