JObject blues: Operation could destabilize the runtime exception

Oct 2, 2010 at 9:09 PM


I am currently working on a site ( and I've incorporated facebook connect into the web app. I connect to facebook through the graph api which returns JSON string content. Authentication is successful, but the parsing of the serialised JSON string into a JObject doesn't work (throws and exception)... This issue is only occuring on the production server (after clicking the myFacebook button), and not on my local machine.

Example code (C#):

//Grab the user's profile info from Facebook:

string fbUser = "" + token;

JObject u = JObject.Parse((string)requestFBData(fbUser));                            //requestFBData reads the content returned by facebook and displays when viewed on label control/text

string userFName = u["first_name"].ToString().Replace("\"", "");                    //this is where the exception happens as shown below -- when i call the u (JObject)

System.TypeInitializationException: The type initializer for 'Newtonsoft.Json.JsonWriter' threw an exception. ---> System.Security.VerificationException: Operation could destabilize the runtime. at Newtonsoft.Json.JsonWriter..cctor() --- End of inner exception stack trace --- at Newtonsoft.Json.JsonWriter..ctor() at Newtonsoft.Json.JsonTextWriter..ctor(TextWriter textWriter) at Newtonsoft.Json.Linq.JToken.ToString(Formatting formatting, JsonConverter[] converters) at Newtonsoft.Json.Linq.JToken.ToString() at KikilikikiShop.FacebookConnect.Page_Load(Object sender, EventArgs e)


I would appreciate a speedy response if possible coz I'm super stuck but I know the light will shine on me... 




Oct 2, 2010 at 10:03 PM

I'm not sure. The error is coming from the JsonWriter static constructor but the only thing that happens there is a static array is created. What version of .NET is your application running in on your local machine and on the server?

Oct 2, 2010 at 11:34 PM
Edited Oct 3, 2010 at 5:10 AM

local: 3.5

server: 2.0 (also allows for running of higher - 3.5)

Oct 3, 2010 at 5:38 AM

Hi James

My site is also using SSL ( ... should it affect the reading of JSON content....

Here is a sample of the JSON content returned:

            {"id":"XXXXXXXXX","name":"Sipho John Vilakati","first_name":"Sipho","middle_name":"John","last_name":"Vilakati","link":"http:\/\/\/sipho","bio":"None much!...","email":"","timezone":2,"locale":"en_GB","verified":true,"updated_time":"2010-09-28T20:33:07+0000"}

Why isn't this string being parsed into my JObject???

I am hoping that you will assist me in sorting out this problem.



Oct 6, 2010 at 11:56 AM

Hi James

I finally got it to work ... However, I used the .Net XmlReader class. I basically take my JSON returned from FB, parse it into an XmlReaderWriterFactory.CreateJsonReader... then return the XmlReader object, which I then assign to an XmlDocument [this document allows me to traverse my XML elements with ease]... Here is a snippet below:

string jsonStr = {"name":"salebona"}

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(JsonReaderWriterFactory.CreateJsonReader(Encoding.ASCII.GetBytes(requestFBData(jsonStr).ToString()), XmlDictionaryReaderQuotas.Max));

And the best part is that, I didn't have to change much of my code because the way JSON.Net accesses its data is almost identical to the XmlDocument methods.

Thank you in advance for your assistance.

Salebona [Swaziland]