DataMember could not be found

青春壹個敷衍的年華 提交于 2019-12-04 23:29:31

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/12687315/datamember-could-not-be-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!