xml serilazation

G

Guest

am trying to inherits membership class and implementing IXmlSerializable but
it doesn't work.


public class SSOMembershipUser : System.Web.Security.MembershipUser
,IXmlSerializable

'SSO.Security.SSOMembershipUser' does not implement interface member
'System.Xml.Serialization.IXmlSerializable.GetSchema()'
 
B

bruce barker

you class says it will implement IXmlSerializable, so have to implement
the methods.

public XmlSchema GetSchema()
{
return null;
}

public void ReadXml(XmlReader reader)
{
// write code to read xml and fill in your object
}

public void WriteXml(XmlWriter writer)
{
// write code to save your object as xml
}


if you object follows all the rules (all public properties are
serializable) and only public get/set properties need saving, then
instead of implementing IXmlSerializable, you can use the [Serializable]
attribute on your class:

[Serializable]
public class SSOMembershipUser
{
}

this is just a flag the the default xmlserialier can serialize the
object. it will throw a runtime error if it finds a property it can not
serialize.


-- bruce (sqlwork.com)
 
G

Guest

Thanks for responding me back.
Actually They are serilizing some properties if I use [Serializable()]
but I have some fields and some properties which are read only like
following I want to have serilaize in XML also. I am using
[XmlRoot("SSOMembershipUser")] and [XmlElement("UserID")] but nothing is
working.

private SSOUser _User = null; //
private SSOUser _LoggedInUser and some properties which are read only like
public int UserID
{
get { return RealUser.UserID; }
}



bruce barker said:
you class says it will implement IXmlSerializable, so have to implement
the methods.

public XmlSchema GetSchema()
{
return null;
}

public void ReadXml(XmlReader reader)
{
// write code to read xml and fill in your object
}

public void WriteXml(XmlWriter writer)
{
// write code to save your object as xml
}


if you object follows all the rules (all public properties are
serializable) and only public get/set properties need saving, then
instead of implementing IXmlSerializable, you can use the [Serializable]
attribute on your class:

[Serializable]
public class SSOMembershipUser
{
}

this is just a flag the the default xmlserialier can serialize the
object. it will throw a runtime error if it finds a property it can not
serialize.


-- bruce (sqlwork.com)

am trying to inherits membership class and implementing IXmlSerializable but
it doesn't work.


public class SSOMembershipUser : System.Web.Security.MembershipUser
,IXmlSerializable

'SSO.Security.SSOMembershipUser' does not implement interface member
'System.Xml.Serialization.IXmlSerializable.GetSchema()'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top