Problem
For the [DataContract] and [DataMember] elements, I can’t discover the namespace to utilize. According to my research, adding the following should suffice, but this is not the case in my instance.
using System;
using System.Runtime.Serialization;
Here’s an example of my code:
using System;
using System.Runtime.Serialization;
namespace MyNamespace {
[DataContract]
public class Tuple<T1, T2> {
// A custom implementation of a Tuple
//...
//...
}
}
And here’s the error I’m getting:
Is it possible that I’m not using the correct namespaces?
Asked by Otiel
Solution #1
The System includes the DataContractAttribute Class. Runtime. namespace for serialization
A reference to System should be added. Runtime. Serialization.dll. However, that assembly isn’t referenced by default. You must manually add an assembly reference to your project by going to References -> Add Reference in the Solution Explorer.
Answered by CD..
Solution #2
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx
You should reference System.Runtime.Serialization.dll because DataContractAttribute is in the System.Runtime.Serialization namespace. It’s only available in.Net versions 3 and up.
Answered by Guillaume
Solution #3
For the.Net 4.0 framework, use Visual Studio.
Answered by Md Kauser Ahmmed
Solution #4
System has the [DataContract] and [DataMember] attributes. The namespace ServiceModel is found in System. ServiceModel.dll is a dll that represents a service model.
System. The System and System are used by ServiceModel. Runtime. To serialize the datamembers, use serialization namespaces.
Answered by Jatin Khurana
Solution #5
I fixed the issue by adding C:Program Files (x86)Reference Assemblies to the path. Microsoft\Framework.NETFramework\v4.0\ The referenced file is System.Runtime.Serialization.dll.
Answered by RotatingWheel
Post is based on https://stackoverflow.com/questions/7401795/namespace-for-datacontract