2

I have Property

public Array Data
    {
        get;
        set;

     }

But I can't serialize it since type Array is not serializable, any Idea how can I achieve this,

Thanx

2 Answers 2

2

You need to give it more information; the simplest it to give it the typed array - for example, with a string array:

public string[] Data {get;set;}

It may (unsure) be possible to send untyped single-dimenstion arrays using [XmlArray] and [XmlArrayItem] to specify the type - but by the time you've done that a typed array would have been easier. I doubt that multi-dimensional arrays are supported.

Sign up to request clarification or add additional context in comments.

3 Comments

I can't since the Data type is unkwonn thats why I kept it as Array
@BreakHead: How about Object[] then? or a collection like List<Object>??
@BreakHead @decyclone XmlSerializer is a typed serializer; it cannot [de]serialize data unless the type is predictable. There are some ways around this if you simply have a restricted set of types, rather than "anything". If the type is actually known to be one of a finite set of possibilities, then please say
1

You can use a List<T> where T is the type of object in your array. Then it will be able to serialize because it knows the Type of object. I believe it serializes like this:

<ArrayOfType>
 <Type>
  <X>value</X>
  <Y>value</Y>
 </Type>
 <Type>
  <X>value</X>
  <Y>value</Y>
 </Type>
</ArrayOfType>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.