Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
I am messing around with a spell checker and I am having a problem De-serializing a dictionary of misspelled words and their suggested spellings. An application sends text to an ASP.NET page. The ASP app performs spell checking and returns a dictionary with the Keys being the misspelled words along with a List of correct suggestions.
Error that I am receiving in VS 2010 when ser.Deserialize is called:
 
An unhandled exception of type 'System.ArgumentException' occurred in System.Web.Extensions.dll
Additional information: Invalid object passed in, member name expected. (1): {"missspelled":["misspelled","miss spelled","miss-spelled","misspelling","misspell","dispelled","misspecified"],"wrods":["words","rods","woods","prods","w rods"]}
 
For the life of me I cannot figure out why the runtime is complaining. Any help would be appreciated.
 
ASP.NET code
 
Dictionary<string, List<string>> WordSuggestions = new Dictionary<string, List<string>>();
...
Populate dictionary with misspelled words and list of suggestions
...
//JSON encode Dictionary and return.
JavaScriptSerializer serializer = new JavaScriptSerializer();
string jsonresult = Server.HtmlEncode(serializer.Serialize(WordSuggestions));
Response.Write(jsonresult);
 
Data as seen/received by App
 
{&quot;missspelled&quot;:[&quot;misspelled&quot;,&quot;miss spelled&quot;,&quot;miss-spelled&quot;,&quot;misspelling&quot;,&quot;misspell&quot;,&quot;dispelled&quot;,&quot;misspecified&quot;],&quot;wrods&quot;:[&quot;words&quot;,&quot;rods&quot;,&quot;woods&quot;,&quot;prods&quot;,&quot;w rods&quot;]}
 
C# App Code (ReturnedSpelling holds the "Data as seen by App" as seen above.
 
JavaScriptSerializer ser = new JavaScriptSerializer();
MispelledWords.text = ser.Deserialize<Dictionary<string, string[]>>(ReturnedSpelling);
 
MispelledWords.text is an appropriate dictionary of type
 
Dictionary<string, string[]>;
 
One thing I just noticed is that in the ASP app, my Dictionary is:
 
Dictionary<string, List<string>> 
and my C# app is:
Dictionary<string, string[]> 
 
Although I can't see why this would be a problem after it has been serialized.
 
...
 
I have since changed my dictionary
string[] to List<string>
on my application (receiving) side. It still does not work...as I suspected. I am serializing then encoding then sending and when the data is returned, decoding and de-serializing in that order.
 
This is what I am using on my application side:
 
Encoding...
HttpUtility.UrlEncode
 
Decoding...
HttpUtility.UrlDecode
Posted 22-Oct-10 7:22am
Edited 23-Oct-10 8:15am
v4
Comments
Sandeep Mewara at 22-Oct-10 13:44pm
   
Well framed and asked.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

These are few pointers. Try this
- Did you check the data whether it is encoded form or not. As are encoding after Serializing, you might need to decode this before DeSerializing.
 
- Also yo are trying to change the type Dictionary<string, List<string>> to Dictionary<string, string[]>
It might be the cause. Don't change the type. You may change it after DeSerializing using various techniques.
 
Also, give some data for WordSuggestions, so that we also can check it
  Permalink  
Comments
willworknow1 at 23-Oct-10 13:26pm
   
WordSuggestions, in each Key, holds a misspelled word that was found (in order to reference it in the original document). The List associated to each Key holds a list of strings that represents the suggested/possible correct spelling for that Key string. You can see the JSON encoded packet above.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

After re reading the posting, I saw the issue.
 
Here was the problem:
 
I was encoding the returned serialized data in the ASP.NET with HtmlEncode but using UrlDecode in the Windows app.
 
Oops.
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 380
1 OriginalGriff 230
2 DamithSL 220
3 Zoltán Zörgő 170
4 Maciej Los 135
0 OriginalGriff 7,740
1 DamithSL 5,694
2 Sergey Alexandrovich Kryukov 5,404
3 Maciej Los 5,061
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 23 Oct 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100