Namespace for [DataContract]

前端 未结 6 2077
一个人的身影
一个人的身影 2020-11-30 18:39

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

相关标签:
6条回答
  • 2020-11-30 18:52

    I solved this problem by adding C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Runtime.Serialization.dll in the reference

    0 讨论(0)
  • 2020-11-30 18:55

    First, I add the references to my Model, then I use them in my code. There are two references you should add:

    using System.ServiceModel;
    using System.Runtime.Serialization;

    then, this problem was solved in my program. I hope this answer can help you. Thanks.

    0 讨论(0)
  • 2020-11-30 18:59

    In visual studio for .Net 4.0 framework,

    1. Try to add new reference to project.
    2. On .Net Tab, Search System.Runtime.Serialization.
    3. Now, you can use using System.Runtime.Serialization. And the error will not be shown.
    0 讨论(0)
  • 2020-11-30 19:09

    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

    0 讨论(0)
  • 2020-11-30 19:12

    [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.

    0 讨论(0)
  • 2020-11-30 19:13

    DataContractAttribute Class is in the System.Runtime.Serialization namespace.

    You should add a reference to System.Runtime.Serialization.dll. That assembly isn't referenced by default though. To add the reference to your project you have to go to References -> Add Reference in the Solution Explorer and add an assembly reference manually.

    0 讨论(0)
提交回复
热议问题