Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - Deserialize array as object

 
 
Old 08-02-2007   #1 (permalink)
sebastian.dau@googlemail.com


 
 

Deserialize array as object

Hello Newsgroup,

I have trouble serializing a data contract that has a data member of
type object.
At runtime this member carries an array of strings and WCF fails to
deserialize this member:
Code:
[DataContract]
public class DC
{
private object _dcvalue;

public DC ()
{}

public DC (object v )
{
_dcvalue = v;
}

[DataMember]
public object DCValue
{
get { return _dcvalue; }
set { _dcvalue = value; }
}
}

The WCF Error Trace reads as follows:
Type 'System.String[]' with data contract name 'ArrayOfstring:http://
schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected.
Add any types not known statically to the list of known types - for
example, by using the KnownTypeAttribute attribute or by adding them
to the list of known types passed to DataContractSerializer.

How do I transfer array types in data members of type objects?

Thanks in advance for your help!

Sebastian Dau.


My System SpecsSystem Spec
Old 08-29-2007   #2 (permalink)
RichQ


 
 

RE: Deserialize array as object

You'll want to add the known type attribute:

[KnownType(typeof(String[]))]

to the DCValue DataMember.

"sebastian.dau@xxxxxx" wrote:
Quote:

> Hello Newsgroup,
>
> I have trouble serializing a data contract that has a data member of
> type object.
> At runtime this member carries an array of strings and WCF fails to
> deserialize this member:
> Code:
> [DataContract]
> public class DC
> {
> private object _dcvalue;
>
> public DC ()
> {}
>
> public DC (object v )
> {
> _dcvalue = v;
> }
>
> [DataMember]
> public object DCValue
> {
> get { return _dcvalue; }
> set { _dcvalue = value; }
> }
> }
>
> The WCF Error Trace reads as follows:
> Type 'System.String[]' with data contract name 'ArrayOfstring:http://
> schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected.
> Add any types not known statically to the list of known types - for
> example, by using the KnownTypeAttribute attribute or by adding them
> to the list of known types passed to DataContractSerializer.
>
> How do I transfer array types in data members of type objects?
>
> Thanks in advance for your help!
>
> Sebastian Dau.
>
>
My System SpecsSystem Spec
Old 04-16-2008   #3 (permalink)


Vista Enterprise x32
 
 

Re: Deserialize array as object

I have the same problem.

But, setting the attribute
[
KnownType(typeof(String[]))]

on a DataMember does not compile.

Error 2 Attribute 'KnownType' is not valid on this declaration type. It is only valid on 'class, struct' declarations.

I hope someone have a solution for this issue....
My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
adding a custom object to array PowerShell
Writing an array back in to an AD Object PowerShell
array or object??? PowerShell
Creating an array of floats using new-object PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46