This project is read-only.

Projections - Newtonsoft.Json.Linq.JObject throwing a Exception - does not contain a definition for 'ContentTypes'

Topics: Troubleshooting
Jun 26, 2013 at 7:31 PM
Has anyone run into any problems with Orchard and Newtonsoft recently?
And more specifically:

When I try to create a projection and add a filter ie ContenType it complains:
An unhandled exception has occurred and the request was terminated. Please refresh the page. If the error persists, go back

'Newtonsoft.Json.Linq.JObject' does not contain a definition for 'ContentTypes'
The json its transposing suggests that it should be fine
  "Description": "",
  "ContentTypes": "Page"
and this is where it is failing (Orchard.Projections.Providers.Filters.ContentTypesFilter):
public LocalizedString DisplayFilter(FilterContext context) {
            string contenttypes = context.State.ContentTypes; //failing here

            if (String.IsNullOrEmpty(contenttypes)) {
                return T("Any content item");

            return T("Content with type {0}", contenttypes);
IEnumerating on the context.State shows it should be there. Ie
(new System.Linq.SystemCore_EnumerableDebugView<System.Collections.Generic.KeyValuePair<string,Newtonsoft.Json.Linq.JToken>>(context.State as Newtonsoft.Json.Linq.JObject)).Items[1]
Key is "ContentTypes" and value is {Page}
quick watch on the line context.State.ContentTypes throws the same error above too.

Anyone any thoughts why it might be causing an exception. Its only occurring to me locally, and has only occurred for the last couple of days. Just updated to the latest tip on source and that didn't help (previous branch was 6 weeks ago).
Jun 27, 2013 at 12:31 AM
However... reinstalling windows (updated to windows 8.1 preview) and installing visual studio 2013 preview then my solution is back up and working properly again.
I guess there was a broken dll somewhere in .Net or cached away somewhere. All is well.
Aug 11, 2013 at 2:50 PM
I'm having the exact same issue. However, I'm using the compiled version, that is, I downloaded and installed the zip version, v1.7 of Orchard. Any idea what I could do? You were talking about a broken dll or cache somewhere, any more precise idea on the subject?

I'm kind of stuck now! Any help would be much appreciated!
Aug 11, 2013 at 3:32 PM
At least I haven't been the only one then!
My solution is running off the main branch from here, and running in IIS Express. Deploying the version was fine, and it was only broken locally.

is that ?

My original thoughts were: VS2012 Update 3, or .Net 4.5.1 was the cause.

I have come across the issue twice... I have not closed down the problem to a single thing as I have not been able to reproduce it when I want it.
Both times i had Update 3 of visual studio 2012 installed.
VS 2013 fell the same way after installing vs 2012 and updating to update 3 (I missed 'web essentials', and 'JustCode', and there wasn't any versions for 2013 at the time).

Now I have VS2012 (only) with update 3 installed - no problems so far. I cant remember if I reinstalled windows 8.1 after the broken point (but would have removed any new .net versions).
Im going to reinstall VS2013 again to see if I hit that problem again.

This part of the web.config was added 4 months ago which should ensure that the right version is running:
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
    <bindingRedirect oldVersion="" newVersion=""/>

Where the problem is im not so sure of now. If it were running in medium trust I would expect to see some permissions errors...

My best answer for now would be to remove the dll from GAC to see if that resolves it. It would have to use the project's file then.
Aug 11, 2013 at 4:03 PM
Good to know! Yes it was I'm using Visual Studio Express for Web. I tought it had something to do with the upgrade since I was using version 1.6.x and then just upgraded to 1.7. It was working fine before that. Maybe something's work with the data, I don't know! I say that but then I recall I just created a new ContentType and a new query and I still get this error...
Aug 11, 2013 at 4:11 PM
Just created an issue for the problem: Hope someone can help us out!
Aug 11, 2013 at 5:32 PM

I've failed to reproduce it this end again. I should have pretty much the same settings as the second time it failed (first on windows 8, second on 8.1)
with VS2012 Update 3 and VS2013 Preview.
Saying that I do remember grabbing a source from codeplex directly (1.6.1) and trying that and it still failed a month ago or so. The steps were simple:
  1. Create site (compact db)
  2. Enable projections
  3. Create Query
  4. Add content type as a filter
  5. After which the error appeared like above on the opened query editor page.
    ... now i cant reproduce it.
    So currently its working here with vs2013 and vs2012 update 3.
    And the cause is still unknown.
Hopefully your broken version may give a few more hints to the puzzle.
Aug 11, 2013 at 10:34 PM
Are you sure it has anything to do with your version of Visual Studio? I say that because I'm using Visual Studio Express and the compiled version so I don't think it has anything to do with it. My production site is running on Windows Server xx with IIS 7 or something like that.

I tried to reset data from my local version (deleted App_Data et Media folders) and created a new DataBase at setup so the site is like a new one but with the exact same code. It worked! I re-created my custom content type, some content and a query with the contenttype filter and I did not get the error.

So I'm guessing it has more to do with the content/data or something.
Aug 12, 2013 at 12:28 AM
Different versions of visual studio - probably not
Differences to the .Net Framework then possibly. New .Net Framework changes have broken many parts of Orchard before.
MVC 4 and Newtonsoft are new to the GAC and could be messing with things, as well as differences to .Net in 4.5.1 ... but I presume as my home pc is happily running all those again with Orchard in VS2012 (update 3) & VS2013 then all is well and stable.

I had many issues:
a equal version of Orchard (in tfs) worked at work but not at home (over several days) which drove me onto the framework broken path (the only part not working was the queries).
Any new solution also showed the same traits with completely new sites, which led to reinstalling Windows when everything worked as normal again on previous and new solutions.

Two of my sites on azure (sql azure databases), which I work on locally as well suffered the same problems, but only locally. I could still sync them and they would be happy online still. It seemed to be only the projection query part that was broken still. This was again alright once windows and visual studio was reinstalled.

I defiantly haven't deleted the app_data on the server, but will have deleted many parts of the the local app_data many times over since then (except site configuration data).

That was my main reasoning for the problem being with the dlls. Its range was over too many of my sites, several of which are actual sites which I work on locally still. So that should reduce the probability on it being the data. It could have been a corrupt or different version of being pulled into app_dependencies. I also would have deleted all the 'obj' and 'bin' folders littered in modules and the web project while testing.
Nov 14, 2013 at 3:13 AM
if the GAC has an old version of NewtownSoft.Json.dll, you may get this kind of error.
Apr 16, 2014 at 9:36 PM
I removed Newtonsoft.json from my GAC and it did not fix the issue.
Apr 18, 2014 at 1:08 AM
Reinstall Newtonsoft.json using the NuGet Package Manager and that fixed the issue