C#에서 DataContract 사용시 참조 처리 문제
DataContract 사용시 참조 문제..
using 선언과
System.Runtime.Serialization 참조를 추가해줘야함.
참조 : http://stackoverflow.com/questions/7401795/namespace-for-datacontract
I can't find the namespace to use for [DataContract]
and [DataMember]
elements. According to what I've found, it seems that adding the following should be enough, but in my case it is not.
using System;
using System.Runtime.Serialization;
Here is a snippet of my code:
using System;
using System.Runtime.Serialization;
namespace MyNamespace {
[DataContract]
public class Tuple<T1, T2> {
// A custom implementation of a Tuple
//...
//...
}
}
And the error I get:
The type or namespace name 'DataContract' could not be found (are you missing a using directive or an assembly reference?)
Am I not using the right namespaces?
--------------------------------------
DataContractAttribute
Class is in the System.Runtime.Serialization
namespace.
But you should add reference to System.Runtime.Serialization.dll
--------------------------------------
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx
DataContractAttribute is in System.Runtime.Serialization namespace and you should reference System.Runtime.Serialization.dll. It's only available in .Net >= 3
--------------------------------------
[DataContract] and [DataMember] attribute are found in System.ServiceModel namespace which is in System.ServiceModel.dll .
System.ServiceModel uses the System and System.Runtime.Serialization namespaces to serialize the datamembers.