abhas

hi friends,

I want to serialize the"System.Windows.Documents.Paragraph" object and for this purpose I have written the following code :

mypara cust = new mypara();
Paragraph ph = new Paragraph(new Run(str));
cust.Para = ph;
cust.Para.Foreground = System.Windows.Media.Brushes.AliceBlue;
string pass = format.Serialize(cust.Para);

mypara is a custom class which contains the Para as an object of Paragraph and during the execution of format.Serialize line I get the error message as Error Serializing System.Windows.Documents.Paragraph.

Note that mypara class is defined having DataContract Attribute and Para is defined under DataMember attribute and I want to pass the string pass generated to the server. Can anyone guide me how to modify the code in order to Serialize System.Windows.Documents.Serialize





Re: Windows Communication Foundation (Indigo) Help Help me please!!!

Zhisheng Huang - MSFT

I am not sure what kind of serializer you are using. What is the type of the "format" object There are several serialization technologies with different programming model.

1. For [DataContract], [DataMember], it is the programming model of DataContractSerializer, see http://msdn2.microsoft.com/en-us/library/ms731072.aspx. Aparently, System.Windows.Document.Paragraph can not be serialized by DataContractSerializer.

2. http://msdn2.microsoft.com/en-us/library/7ay27kt9.aspx talks about BinaryFormatter and XmlSerializer

3. WPF also has its own serialization techonology, XamlReader/XamlWriter. Looks like this is the serialization techonology for those types. Here are a few docs and you can ask related question on the WPF forum http://forums.microsoft.com/MSDN/ShowForum.aspx ForumID=119&SiteID=1

http://msdn2.microsoft.com/en-us/library/system.windows.markup.xamlreader.aspx

http://msdn2.microsoft.com/en-us/library/system.windows.markup.xamlwriter.aspx

http://msdn2.microsoft.com/en-us/library/ms747122.aspx





Re: Windows Communication Foundation (Indigo) Help Help me please!!!

abhas

hi Zhisheng,

I gone through the useful links you provided for me and after studying that I successfully implemented the serialization of System.Windows.Documents.Paragraph. I am using ObjectStateFormatter of System.Web.UI namespace to serialize the objects into string and then passing it to other machine, but when I deserialize the string into object I recieve an error that the "serialized data is invalid" if you know how to solve this error than please guide me through.

I am giving you the code of the custom class which I created to serialize and during the execution of the statement I recieve the error. Hope it helps you to solve the error.

[Serializable]
public sealed class Singleton : Paragraph, ISerializable, IObjectReference
{
// This is the one instance of this type.
private Singleton theOneObject;

// Here are the instance fields.
private string someString_value;
private Int32 someNumber_value;

public string SomeString
{
get { return someString_value; }
set { someString_value = value; }
}

public Int32 SomeNumber
{
get { return someNumber_value; }
set { someNumber_value = value; }
}

// Private constructor allowing this type to construct the Singleton.
public Singleton(Inline obj) : base(obj)
{
// Do whatever is necessary to initialize the Singleton.
//someString_value = "This is a string field";
//someNumber_value = 123;
}

public Singleton()
{

}

// A method returning a reference to the Singleton.
public Singleton GetSingleton()
{
return theOneObject;
}

public Singleton GetObject(Inline obj)
{
theOneObject = new Singleton(obj);
return theOneObject;
}

// A method called when serializing a Singleton.
[SecurityPermissionAttribute(SecurityAction.LinkDemand,
Flags = SecurityPermissionFlag.SerializationFormatter)]
void ISerializable.GetObjectData(
SerializationInfo info, StreamingContext context)
{
info.SetType(typeof(Singleton));
// No other values need to be added.
}

public Object GetRealObject(StreamingContext context)
{
// When deserialiing this object, return a reference to
// the Singleton object instead.
return this.GetSingleton();
}
// Note: ISerializable's special constructor is not necessary
// because it is never called.
}

I recieve an error executing the following statement :

Singleton ph = (Singleton)format.Deserialize(s);

if you don't understand or need some more information then please convey it to me.






Re: Windows Communication Foundation (Indigo) Help Help me please!!!

Zhisheng Huang - MSFT

I don't know about ObjectStateFormatter. System.Web.UI is one of the namespace of ASP.NET techonology. You could try to ask the question there. By the way, when you mention you receive an error when executing the program, you'd better post the detail of the error so others can help you better, otherwise people have to guess your error.