DataContractJsonSerializer Serializes item, then cannot deserializ

Tech-Archive recommends: Speed Up your PC by fixing your registry



the JSON that is being emitted is being stored in a DB as an object state,
then fails to deserialize properly from that value. We've simplified it,
bypassing the database, encoding, etc and it still fails, however we are
serializing the exact same types in other areas of the application using the
same shared method and they all work just fine.

Here is the JSON that it is blowing up on:

"[{\"CLRTypeName\":\"DateTime\",\"Defaultvalue\":\"11\\\/22\\\/2008\",\"ParameterName\":\"StartDate\",\"ParameterType\":\"3\",\"ParameterValue\":\"\",\"Prompt\":\"Start
Date\",\"ValueList\":[]},{\"CLRTypeName\":\"DateTime\",\"Defaultvalue\":\"12\\\/22\\\/2008\",\"ParameterName\":\"EndDate\",\"ParameterType\":\"3\",\"ParameterValue\":\"\",\"Prompt\":\"End
Date\",\"ValueList\":[]},{\"CLRTypeName\":\"Int32\",\"Defaultvalue\":\"-1\",\"ParameterName\":\"LeaveReason\",\"ParameterType\":\"1\",\"ParameterValue\":\"-1\",\"Prompt\":\"Leave
reason\",\"ValueList\":[\"-1|- ALL -\",\"10|ADOPT - Adoption\",\"1|BIRTH -
Birth of a Child\",\"14|BONEMARROW - Bone Marrow Donation\",\"8|ACTIVEDUTY -
Emergency Active Duty\",\"4|EMPHEALTH - Employee illness, injury, or health
condition\",\"18|ENLIST - Enlistment\",\"29|FMQE - Family Member Qualifying
Exigency\",\"23|SHCMIL - Family Military Member SHC\",\"3|FAMHEALTH - Family
Serious Health Condition\",\"11|FOSTER - Foster Placement\",\"13|ORGAN -
Organ Donation\",\"12|PREGMATERN - Pregnancy \\\/ Maternity\",\"19|RESERVE -
Reserve Duty\",\"15|SICKCHILD - Sick Child\",\"30|UNMGD -
Unmanaged\",\"21|WORK - Work Related Illness or
Injury\"]},{\"CLRTypeName\":\"Int32\",\"Defaultvalue\":\"-1\",\"ParameterName\":\"WorkType\",\"ParameterType\":\"1\",\"ParameterValue\":\"-1\",\"Prompt\":\"WorkType\",\"ValueList\":[\"-1|-
ALL -\",\"1|Continuous Leave\",\"2|Intermittent Leave\",\"7|Medical
Only\",\"3|Reduced Schedule Leave\",\"0|No Lost
Time\"]},{\"CLRTypeName\":\"Int32\",\"Defaultvalue\":\"-1\",\"ParameterName\":\"Location\",\"ParameterType\":\"1\",\"ParameterValue\":\"-1\",\"Prompt\":\"Location\",\"ValueList\":[\"-1|-
ALL -\",\"3|SPARTANBURG REGIONAL HEALTHCARE SYSTEM -
..\"]},{\"CLRTypeName\":\"bool\",\"Defaultvalue\":\"1\",\"ParameterName\":\"IncludeALL\",\"ParameterType\":\"5\",\"ParameterValue\":\"1\",\"Prompt\":\"Include
All
(internal)\",\"ValueList\":[]},{\"CLRTypeName\":\"string\",\"Defaultvalue\":\"WORK\",\"ParameterName\":\"OrgTypeCode\",\"ParameterType\":\"2\",\"ParameterValue\":\"WORK\",\"Prompt\":\"Org
Type Code
(internal)\",\"ValueList\":[]},{\"CLRTypeName\":\"Guid\",\"Defaultvalue\":\"\",\"ParameterName\":\"UserId\",\"ParameterType\":\"6\",\"ParameterValue\":\"\",\"Prompt\":\"Calling
UserID\",\"ValueList\":[]},{\"CLRTypeName\":\"Int32\",\"Defaultvalue\":\"
\",\"ParameterName\":\"PersonID\",\"ParameterType\":\"1\",\"ParameterValue\":\"7\",\"Prompt\":\"Visibility
As\",\"ValueList\":[]},{\"CLRTypeName\":\"bool\",\"Defaultvalue\":\"\",\"ParameterName\":\"ShowPeers\",\"ParameterType\":\"5\",\"ParameterValue\":\"1\",\"Prompt\":\"Show Peers\",\"ValueList\":[]}]"

And then we tried a simple XmlObjectSerializer for the same type and
recieved the same error (here's the object Xml string that was generated and
failed):

"<ArrayOfReportParameter
xmlns=\"http:\/\/schemas.datacontract.org\/2004\/07\/iAM.Reporting.BLL.BusinessObjects\"
xmlns:i=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"><ReportParameter><CLRTypeName>DateTime<\/CLRTypeName><Defaultvalue>11\/22\/2008<\/Defaultvalue><ParameterName>StartDate<\/ParameterName><ParameterType>3<\/ParameterType><ParameterValue\/><Prompt>Start
Date<\/Prompt><ValueList
xmlns:a=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/Arrays\"\/><\/ReportParameter><ReportParameter><CLRTypeName>DateTime<\/CLRTypeName><Defaultvalue>12\/22\/2008<\/Defaultvalue><ParameterName>EndDate<\/ParameterName><ParameterType>3<\/ParameterType><ParameterValue\/><Prompt>End
Date<\/Prompt><ValueList
xmlns:a=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/Arrays\"\/><\/ReportParameter><ReportParameter><CLRTypeName>Int32<\/CLRTypeName><Defaultvalue>-1<\/Defaultvalue><ParameterName>LeaveReason<\/ParameterName><ParameterType>1<\/ParameterType><ParameterValue>-1<\/ParameterValue><Prompt>Leave
reason<\/Prompt><ValueList
xmlns:a=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/Arrays\"><a:string>-1|-
ALL -<\/a:string><a:string>10|ADOPT - Adoption<\/a:string><a:string>1|BIRTH -
Birth of a Child<\/a:string><a:string>14|BONEMARROW - Bone Marrow
Donation<\/a:string><a:string>8|ACTIVEDUTY - Emergency Active
Duty<\/a:string><a:string>4|EMPHEALTH - Employee illness, injury, or health
condition<\/a:string><a:string>18|ENLIST -
Enlistment<\/a:string><a:string>29|FMQE - Family Member Qualifying
Exigency<\/a:string><a:string>23|SHCMIL - Family Military Member
SHC<\/a:string><a:string>3|FAMHEALTH - Family Serious Health
Condition<\/a:string><a:string>11|FOSTER - Foster
Placement<\/a:string><a:string>13|ORGAN - Organ
Donation<\/a:string><a:string>12|PREGMATERN - Pregnancy \/
Maternity<\/a:string><a:string>19|RESERVE - Reserve
Duty<\/a:string><a:string>15|SICKCHILD - Sick
Child<\/a:string><a:string>30|UNMGD - Unmanaged<\/a:string><a:string>21|WORK
- Work Related Illness or
Injury<\/a:string><\/ValueList><\/ReportParameter><ReportParameter><CLRTypeName>Int32<\/CLRTypeName><Defaultvalue>-1<\/Defaultvalue><ParameterName>WorkType<\/ParameterName><ParameterType>1<\/ParameterType><ParameterValue>-1<\/ParameterValue><Prompt>WorkType<\/Prompt><ValueList
xmlns:a=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/Arrays\"><a:string>-1|-
ALL -<\/a:string><a:string>1|Continuous
Leave<\/a:string><a:string>2|Intermittent
Leave<\/a:string><a:string>7|Medical Only<\/a:string><a:string>3|Reduced
Schedule Leave<\/a:string><a:string>0|No Lost
Time<\/a:string><\/ValueList><\/ReportParameter><ReportParameter><CLRTypeName>Int32<\/CLRTypeName><Defaultvalue>-1<\/Defaultvalue><ParameterName>Location<\/ParameterName><ParameterType>1<\/ParameterType><ParameterValue>-1<\/ParameterValue><Prompt>Location<\/Prompt><ValueList
xmlns:a=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/Arrays\"><a:string>-1|-
ALL -<\/a:string><a:string>3|SPARTANBURG REGIONAL HEALTHCARE SYSTEM -
..<\/a:string><\/ValueList><\/ReportParameter><ReportParameter><CLRTypeName>bool<\/CLRTypeName><Defaultvalue>1<\/Defaultvalue><ParameterName>IncludeALL<\/ParameterName><ParameterType>5<\/ParameterType><ParameterValue>1<\/ParameterValue><Prompt>Include
All (internal)<\/Prompt><ValueList
xmlns:a=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/Arrays\"\/><\/ReportParameter><ReportParameter><CLRTypeName>string<\/CLRTypeName><Defaultvalue>WORK<\/Defaultvalue><ParameterName>OrgTypeCode<\/ParameterName><ParameterType>2<\/ParameterType><ParameterValue>WORK<\/ParameterValue><Prompt>Org
Type Code (internal)<\/Prompt><ValueList
xmlns:a=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/Arrays\"\/><\/ReportParameter><ReportParameter><CLRTypeName>Guid<\/CLRTypeName><Defaultvalue\/><ParameterName>UserId<\/ParameterName><ParameterType>6<\/ParameterType><ParameterValue\/><Prompt>Calling
UserID<\/Prompt><ValueList
xmlns:a=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/Arrays\"\/><\/ReportParameter><ReportParameter><CLRTypeName>Int32<\/CLRTypeName><Defaultvalue>
<\/Defaultvalue><ParameterName>PersonID<\/ParameterName><ParameterType>1<\/ParameterType><ParameterValue>7<\/ParameterValue><Prompt>Visibility
As<\/Prompt><ValueList
xmlns:a=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/Arrays\"\/><\/ReportParameter><ReportParameter><CLRTypeName>bool<\/CLRTypeName><Defaultvalue\/><ParameterName>ShowPeers<\/ParameterName><ParameterType>5<\/ParameterType><ParameterValue>1<\/ParameterValue><Prompt>Show
Peers<\/Prompt><ValueList
xmlns:a=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/Arrays\"\/><\/ReportParameter><\/ArrayOfReportParameter>"


Finally, here is the error and stack trace we're getting back form the
deserializer:

2008-12-22 17:47:07,851 [3] ERROR
iAM.Reporting.BLL.BusinessObjects.ReportSubscription [(null)] -
ReportParameters::Get() Exception:
System.Runtime.Serialization.SerializationException: There was an error
deserializing the object of type
System.Collections.Generic.List`1[[iAM.Reporting.BLL.BusinessObjects.ReportParameter,
iAM.Reporting.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].
The token '"' was expected but found '\'. Line 1, position 31. --->
System.Xml.XmlException: The token '"' was expected but found '\'. Line 1,
position 31.
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader
reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlExceptionHelper.ThrowTokenExpected(XmlDictionaryReader
reader, String expected, Char found)
at System.Xml.XmlUTF8TextReader.ReadAttributes()
at System.Xml.XmlUTF8TextReader.ReadStartElement()
at System.Xml.XmlUTF8TextReader.Read()
at System.Xml.XmlBaseReader.IsStartElement()
at System.Xml.XmlBaseReader.IsStartElement(XmlDictionaryString localName,
XmlDictionaryString namespaceUri)
at
System.Runtime.Serialization.XmlReaderDelegator.IsStartElement(XmlDictionaryString localname, XmlDictionaryString ns)
at
System.Runtime.Serialization.XmlObjectSerializer.IsRootElement(XmlReaderDelegator
reader, DataContract contract, XmlDictionaryString name, XmlDictionaryString
ns)
at
System.Runtime.Serialization.DataContractSerializer.InternalIsStartObject(XmlReaderDelegator reader)
at
System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
at
System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
--- End of inner exception stack trace ---
at
System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
at
System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(Stream
stream)
at iAM.Core.Common.SerializationObject.DeserializeObject(String
objectAsSerializedString, XmlObjectSerializer serializer)
at iAM.Core.Common.SerializationObject.DeserializeObject(String
objectAsSerializedString, Type objectType)
at
iAM.Reporting.BLL.BusinessObjects.ReportSubscription.get_ReportParameters()
in C:\VSTS_SRC\Source
Code\iAM.Reporting\iAM.Reporting.BLL\BusinessObjects\ReportSubscription.cs:line 121


Any help would be greatly appreciated.

Thanks,

--
Chad Scharf
_______________________________
http://www.chadscharf.com
.



Relevant Pages

  • RE: DataContractJsonSerializer Serializes item, then cannot deserializ
    ... serialized JSON string going in, however was only attemptnig to deserialize ... then fails to deserialize properly from that value. ... serializing the exact same types in other areas of the application using the ... reader, String res, String arg1, String arg2, String arg3) ...
    (microsoft.public.dotnet.framework)
  • Re: Invariant with DIGIT-CHAR-P and the reader.
    ... How else would the producer of such a string mean it to be ... CL reader parses as numbers things that "look like a number". ... > treated in ways that a naive Lisp program might be trying to mimic ... if your data contains Unicode characters, ...
    (comp.lang.lisp)
  • Re: SqlDataReader Function From a VB6 refugee
    ... Also the Reader is for connected operations i.e. the underlying connection ... Shared Function Create_SQL_DataReader(ByVal sDate As String) As ... Dim SQLConn As New SqlConnection ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: inputstream -> string
    ... den aus dem Reader gelesenen char-Buffer ... StringWriter sw = new StringWriter; ... Kein Encoding anzugeben, ... private String readStream ...
    (de.comp.lang.java)
  • Re: pumping lemma (third try)
    ... Mark, you should trim your replies to what's relevant. ... This saves the reader from having to scroll past a lot of ... > since the string 1 appears as an adjacent repeat at the end). ... > I have tried to be as precise as a wannabe like me can be. ...
    (comp.theory)