This project has moved. For the latest updates, please go here.

Problem and deserializing into dynamic objects for MS Razor engine.

Sep 27, 2012 at 2:50 PM

I am trying to use to deserialize JSON input into dynamic objects, but instead of containing primitives, the dynamic object contains values of type Newtonsoft.Json.Linq.JObject.

The difference can be easily replicated with the following code for comparison purposes:


var jsonTemplate = @"{ ""UserName"": ""eezewski"", ""FullName"": ""EvanEzewski"", ""Password"": ""fakepassword"", ""LoginUrl"": ""http: //""}";
var model = jsonSerializer.Deserialize<dynamic>(new JsonTextReader(new StringReader(jsonTemplate)));
dynamic model2 = new
                            UserName = "eezewski",
                            FullName = "Evan Ezewski",
                            Password = "fakepassword",
                            LoginUrl = ""


This causes the MS Razor engine to throw an exception when trying to parse a cshtml template.

Error CS1061: 'Newtonsoft.Json.Linq.JObject' does not contain a definition for 'FullName' and no extension method 'FullName' accepting a first argument of type 'Newtonsoft.Json.Linq.JObject' could be found (are you missing a using directive or an assembly reference?)} System.CodeDom.Compiler.CompilerError.

Unfortunately, this one problem is preventing us from using your otherwise wonderful library in our Razor solutions.

If anyone knows of a workaround or a trick to getting this working correctly, it would be greatly appreciated; otherwise we're going to have to look elsewhere.



May 4, 2015 at 9:19 PM
I'm getting the same issue :(