Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Indigo

Deserialize array as object

 
 
Thread Tools Display Modes
Old 08-02-2007   #1 (permalink)
sebastian.dau@googlemail.com
Guest
 
Posts: n/a

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.

 
Old 08-29-2007   #2 (permalink)
RichQ
Guest
 
Posts: n/a

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.
>
>
 
Old 04-16-2008   #3 (permalink)
Newbie
thobj is on a distinguished road
 
Join Date: Apr 2008
Vista Enterprise x32
Posts: 1

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....
thobj is offline  
 
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing an array back in to an AD Object Mark Holland PowerShell 7 04-23-2008 04:52 AM
array or object??? Ryan PowerShell 5 03-11-2008 05:41 PM
preventing PS from Casting object to an array Marclown PowerShell 3 01-31-2008 01:21 PM
Creating an array of floats using new-object Kris PowerShell 2 11-27-2007 10:56 AM








Vistax64.com 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 2005-2008

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 47 48 49