Serializing objects to JSON with properties that return interfaces

I want to serialize and deserialize an object to and from JSON. My
code looks something like this:

http://pastebin.com/yB5idwNq

This gives me an error like this:

System.Runtime.Serialization.SerializationException: Type 'MyObject1'
with data contract name 'MyObject1:http://schemas.datacontract.org/
2004/07/namespace' 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.

I am only using ISerializable because [Serializable] [DataContract]
would not work of course. The main problem I think I am having is that
I have declared my return type as an interface.

I don't want to change my objects and it is actually important that I
return the interface and not the implementation for various reasons.
What can be done? if Serializable or DataContract attributes won't
work automatically, can I pull this off manually using Serializable?
0
Ra
3/14/2010 2:18:03 PM
dotnet.framework.aspnet 1425 articles. 0 followers. Follow

1 Replies
563 Views

Similar Articles

[PageSpeed] 35

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/6b70e9f4-52bc-4fa9-a0ff-c0859e041e85
http://blogs.msdn.com/sowmy/archive/2006/06/06/all-about-knowntypes.aspx

Please post your solution after you figure out, so others can learn from it.





"Ra Carter" <spacemonkeyiv@gmail.com> wrote in message 
news:172f43fb-c4e1-47b6-b433-47600b46525b@k17g2000yqb.googlegroups.com...
>I want to serialize and deserialize an object to and from JSON. My
> code looks something like this:
>
> http://pastebin.com/yB5idwNq
>
> This gives me an error like this:
>
> System.Runtime.Serialization.SerializationException: Type 'MyObject1'
> with data contract name 'MyObject1:http://schemas.datacontract.org/
> 2004/07/namespace' 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.
>
> I am only using ISerializable because [Serializable] [DataContract]
> would not work of course. The main problem I think I am having is that
> I have declared my return type as an interface.
>
> I don't want to change my objects and it is actually important that I
> return the interface and not the implementation for various reasons.
> What can be done? if Serializable or DataContract attributes won't
> work automatically, can I pull this off manually using Serializable? 


0
sloan
3/17/2010 2:36:40 AM
Reply:

Similar Artilces:

XP Interface...
Hello All, Just out of curiosity, when I select Connect to my Bank and the dialog box comes up, why doesn't the title bar of the Update dialog window use the XP interface? -U Because they didn't program it to work this way? M05 seems to pretty much ignore the operating system scheme and styles and UI conventions and so forth. Perhaps this is because it's too complicated to make it work correctly on all of the different operating systems supported. Perhaps this is because the Money designers think they know better. Who knows? "Steve Thompson" <stthomp@hotma...

ShapeSheet: Inserting a Custom Property & displaying it via Automation -- Visio 2002
I've been customizing some of the existing Visio shapes for use at work. Through the ShapeSheet, I've added the necessary custom properties and figured out a (ham-fisted, in my opinion) approach to displaying the custom properties in the shape. I'd like to find a better way of doing this, preferably through a macro that will allow me to, for any given shape, add a custom property (with associated attributes) and display that new text appended to the existing displayed text. I can do this by hand, but I'd rather have core shapes that can be easily extended. Right now, using ...

NdisMRegisterScatterGatherDma returns NDIS_STATUS_RESOURCES on 64 bit
Hi, When i call the NdisMRegisterScatterGatherDma on 64 bit 2008 system, it returns NDIS_STATUS_RESOURCES always, whereas, if i use this API on 32 bit 2008 system, it returns appropriate handle. Any clues... Regards, Naresh (Microsoft India Community Star) How are you calling this function? A code snippet would help. More to the point, what are you setting DmaDescription->Flags to? "Naresh" <narsha@gmail.com> wrote in message news:212a9ba8-0d9c-4f71-a1f2-41ac081c6822@a2g2000prd.googlegroups.com... > Hi, > > When i call the NdisMRegisterScat...

External objects
Hi, When passing a node set into a method defined in an external object, what is the best type to use for the parameter? Similarly for returning a node set. Regards ...

How to set default language for all text and object in DOCX file.
I have to review a large DOCX file. This file was translated and the translator left lots of text fields in drawing canvas and other places in wrong language. Is there any possibility how to set in Word all the text to one language? Ctrl+A does not works for all objects. My document must be in German and I have some German text set as Czech or English. -- Regards Jan Kratochvil Windows Vista Business SP2, Office 2007 SP 2 It is much the same process as updating fields in story ranges. The following should work Sub German() Dim oStory As Range For Each oStory In ...

unknown object in cell
a black and gray object like a radio button appeared in the upper left corner of a cell after a cut/paste action. there was a radio button in the original document next to the text I was copying. when you click on it, the toolbars go gray, and the object changes like a radio button, but nothing else appears to happen. nothing happens on right-click. this object obscures part of the text in this cell. what is it and how do I get rid of it? If it's the only object, you can use Edit-->Go to-->Special-->Objects and hit Delete. Otherwise, use the selector tool on the drawing too...

When uploading doc to SharePoint, date property of doc not transferred to SP Metadata
A little background: I have a large collection of excel and word documents that I would like to upload to SharePoint (WSS 3.0). I have been able to populate the custom document properties of these files and would like to have SharePoint's metadata/columns to have the values of these custom properties that I have set. To get the data into Sharepoint, I created columns with the same name and data type of the custom properties of the documents. I then uploaded the documents into SharePoint. Everything pulls into SharePoint except for a date that is defined in the custom properties....

I can't get DateTime to serialize to just date
I have an xml element that has a child element of type date. My class has a corresponding member of type DateTime. I set the member to just the date portion of a DateTime. When I serialize, I get a zeros for the time part like this 2003-11-14T00:00:00.000000-06:00. The server that is receiving this code expects only a date since that is what the schema specifies and so it doesn't handle this properly. How do I get my DateTime member to serialize to just the date portion? Reggie Reggie, Add [XmlElement(DataType="date")] // "date" refers to the XML Schema...

how do i use the daye function to insert a serial number
how do i use the date function to insert a formula that inserts a serial number for a specific date If you format the cell where the date is entered as 'number' then this gives a unique number. However I suspect what you need is not so simple and therefore requires fuller explanation please. -- Russell Dawson Excel Student Please hit "Yes" if this post was helpful. "stephanieylalo" wrote: > how do i use the date function to insert a formula that inserts a serial > number for a specific date See help on DATEVALUE function. ...

cannot insert object error
hi, am getting cannot insert object error in case of VSTO application on some machines. am trying to do controls.addcontrol. Can you please post the code you are using. -- Regards, OssieMac "Jagadeesh" wrote: > hi, > am getting cannot insert object error in case of VSTO application on some > machines. > am trying to do controls.addcontrol. its a simple code where i am doing controls.AddButton / AddControl. this.Controls.AddButton(10, 10, 100, 100,"test"); Thanks, Jagadeesh "OssieMac" wrote: > Can you ple...

Publisher 2003 Printing Style Properties
Is there any way to print out a listing of the properties of each style, similar to doing so in MS Word 2003? I have a lot of custom styles and can not for the life of me remember all the various permutations. ...

If it returns #N/A, making it return 0
I have a list of numbers, that at the end of their row it averages them. However, the numbers are obtained by a VLOOKUP function. If it can't find what it's looking for, it returns #N/A which makes it so it can't calculate the average at the end. Is there any way to get the VLOOKUP function to return 0 instead of #N/A? Or maybe make the cell return 0 if the VLOOKUP function returns #N/A? ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from http://www.ExcelForum.com/ Also, if it return...

How can I compare two colums and if equal return the figure in th.
Subject says it all. I have two columns which I need to compare from different workbooks and if they are equal I need the result of a corresponding row in another column. Thanks SEAN KERR Hi have a look at VLOOKUP for this -- Regards Frank Kabel Frankfurt, Germany "Sean" <Sean@discussions.microsoft.com> schrieb im Newsbeitrag news:20D90E3E-08D0-4176-B416-EB841E873834@microsoft.com... > Subject says it all. I have two columns which I need to compare from > different workbooks and if they are equal I need the result of a > corresponding row in another column. > ...

Using grid class directly with CRecordset object
How can I use several columns in CListBox ? Is there any other control box with several columns ? Can you give me a pointer to find a grid class which I can use with CRecordset object directly ? You can use a CListCtrl to show multiple columns or you can use something like this: http://www.codeproject.com/miscctrl/flexgrid.asp Or something like: http://www.theultimatetoolbox.com/products/ultimategrid/ That has ADO built in. You have to pay for Ultimate Grid, but it's a nice bit of code. Tom "Alur" <Alur@discussions.microsoft.com> wrote in message news:145BD1A1-...

Query which Value Returns Previous Record
I'm very new to access so please forgive me. I have a query that points to a table and returns a response based on a certain value. I was wondering if anyone could show me what to type in the query design view that if the value (example John Smith) is found report back not only that specific record but the previous record located above. Any help would be much appreciated. A thousand thanks Johnny Mac Hi Johnny, A mental picture that you should have for records in a table, within a JET ("Access") database is like fish in an aquarium. So, locating "the p...

When an RMA is received the returned items have a status of availa
When an RMA is received all returned items have a status of available. This can cause issues where the return site is also used as a stock site on sales orders, the returned items can be allocated. This then causes problems if the returned item is to be scrapped or RTV'd. Either users should be able to choose what status the returned items have or returned items should not have a status of available. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" but...

missing object library
I am trying to insert a Calendar Control an Excel 2003 worksheet. When I try to select Insert | Object and choose Calendar Control 11.0 there is no listing for Calendar Control 11.0! Any ideas? Thanks Hi Eagle7, Go to Tools/Macro/Visual Basic Editor While in Visual Basic go to Tools/References I believe you'll find it there Larry -- keithl816 ------------------------------------------------------------------------ keithl816's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=21287 View this thread: http://www.excelforum.com/showthread.php?threadid=48...

error message Operation failed. An object could not be found
I not have Microsoft Outlook and would like to use it instead of Outlook Express. I followed all the instructions for moving information from Outlook Express to Microsoft Outlook and it all moved. I cannot send or received messages through Microsoft outlook. You need to set your "account" up. What version of Outlook do you use? Who is your ISP? (Internet Service Provider) -- Nikki Peterson [MVP - Outlook] "Bonnie" <bholland3@kc.rr.com> wrote in message news:053c01c39520$15b2b030$a401280a@phx.gbl... I not have Microsoft Outlook and would like to use it i...

Is there a way to align multiple marked objects (to a leftmost object)?
From other, similar tools I know that I can mark multiple objects (e.g. rectangle boxes) and hit a magic hotkey. All objects are then vertically left align according to the FIRST marked object. Or horizontally bottom aligned depending on the hotkey. Is there something similar in Visio? Cam On 14 Nov 2008 19:03:01 GMT, cpet_magnus@hotmail.com (Camille Petersen) wrote: >From other, similar tools I know that I can mark multiple objects (e.g. rectangle boxes) >and hit a magic hotkey. All objects are then vertically left align according to the FIRST marked object. > >Or horizontall...

Create More than 1 Return for Same Invoice !!!
Hello In version 10.0. The RMA can create more than 1 return for same sales invoice! Is there any possibility to disable this properties? I need to prohibit anyone to create more than 1 return for same invoice. Any suggest ? no, that cannot be disabled. Too many firms have more than one return per invoice and it is not an option -- Richard L. Whaley Author / Consultant / MVP Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at http://www.AccoladePublications.com "Monzer Osama" wrote: > Hello > In version 10.0. > The R...

Re: Writing a resume I'm not sure what I write in objectives #7
"GbH" <Geoff_Hannington@IEE.ORGasm> wrote in message news:... > > "GbH" <Geoff_Hannington@IEE.ORGasm> wrote in message news:... >> >> "Ed Bennett" <the_nerd@mvps.org> wrote in message >> news:eP#YfN65JHA.2656@TK2MSFTNGP05.phx.gbl... >>> GbH wrote: >>>> but neither is a resume!!!! >>> >>> So you're complaining about the lack of acute accents when people >>> refer to a r�sum� as a resume? Why not correct to the intended word >>> rather than a different one - pa...

Item Extension record required for all items in Returns Management
We've been testing the Returns Management module using the Fabrikam company to see if it will be something we can benefit from. Our testing has shown that in order for the system to pull the item's Current Cost (from the Item Master), you must create an Item Extension record for the item and check the box marked 'Use Current Cost'. If you don't create the record, the system will default to a zero cost. (This assumes that you don't associate the return with an existing invoice where the customer bought the item). To me, this seems to be a maintenance nightmare. O...

acmStreamPrepareHeader returns MMSYSERR_INVALPARAM
I'm trying to compress A/u Law 8000 KHz 8 bits stereo wave files into TrueSpeech waves (they are human voice wave files). To do so, I built the Visual Studio Sample "acmapp" and running it I found out that I should convert my original file into PCM 8000 KHz 16 bits stereo, then to PCM 8000 KHz 16 bits mono, then TrueSpeech. It worked fine. Now, I'm trying to do this programmatically. But when my code invokes "acmStreamPrepareHeader" I get an error: MMSYSERR_INVALPARAM (at least one parameter is invalid). I reviewed my code, where those parameters are formed, and ...

How to make an object to survive application restart?
My application in vb.net is using a collection of structures, implementing basically a queue of jobs. What is the easiest way to make this collection surviving application restart? Is there some embedded universal way to save each member of the collection, for example to an XML file, and then restore them upon restart? I understand that I can code the export of every particular object, but thought maybe there's some universal way like object.ExportToXML <path> / object = loader.load <path> thanks Vadim, You will want to take a look at either Serialization (using...

External Error
Dear all, recently, we dropped a domain-control (Other DCs remain), other servers and clients can work well, but CRM server cannot work, the dialog will appear that (External Error - No Such Object On Server. "The selected object could not be found. Verify that the object exists in both the database and Active Directory.") Then I reinstalled SQL server (and use sp_attachDB to attach the original CRM databases). Then reinstalled the CRM Server 1.2 software. After that, the problem remains. (1) Which object ? (2) where to verify? (3) How to correct? Please urgently help me. Bec...