DataMember could not be found

20,602

Solution 1

I have solved the problem. I just removed the System.Runtime.Serialization in the references in the project explorer and addded it by browsing then it worked. Weird.

Solution 2

Remove System.Runtime.Serialization from code, then add from menu > Project > Add reference ..> . Then again add into code. it works.

Share:
20,602
SleepNot
Author by

SleepNot

Just another IT Enthusiast :) SOreadytohelp

Updated on July 27, 2020

Comments

  • SleepNot
    SleepNot almost 4 years

    As I have done my research regarding this problem of mine, I still have no luck in solving my error of Error 1 The type or namespace name 'DataMember' could not be found (are you missing a using directive or an assembly reference?)

    I have come across a solution stating that I should reference System.Runtime.Serialization but still I am having no luck even when add reference to it.

    Here is my code:

    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.Serialization;
    using System.Xml.Serialization;
    
    namespace WebServApp
    {
        [Serializable]
        public class Employee
        {
            [DataMember]
            public int EmpNo { get; set; }
            [DataMember]
            public string EmpName { get; set; }
            [DataMember]
            public int DeptNo { get; set; }
            [DataMember]
            public int Salary { get; set; }
        }
    }
    

    and this is the tutorial that I am actually trying to follow: http://www.dotnetcurry.com/ShowArticle.aspx?ID=472

    Can anyone help me with this error?

  • josef
    josef over 11 years
    Yes, you wrote [Serializable] instead of DataContract . Org:[DataContract(Name = "Employee", Namespace = "")] public class Employee { [DataMember] public int EmpNo { get; set; } [DataMember] public string EmpName { get; set; } [DataMember] public int DeptNo { get; set; } [DataMember] public int Salary { get; set; } }. Sometimes copy and paste is your friend.
  • SleepNot
    SleepNot over 11 years
    Nope. The [Serializable] wasnt the problem. I just did what I did on my answer above. When it worked, I actually removed the [Serializble] in the code but it still worked.
  • pwnsauce
    pwnsauce over 10 years
    Once you're in the Reference Manager, you'll find System.Runtime.Serialization under the Assemblies > Framework tab.