I'm making an API controller that is supposed to send content over requests.
On a project created in 8.1.5 I have no issues with accessing content of a specific type like this:
Home home = Umbraco.ContentAtXPath("//home").OfType<Home>().First();
The 8.1.5 is a project I use for testing things out before moving to the commercial project.
However, if I try and do the exact line of code on the actual project (which is in 8.2.2) the Home (or whatever type) is just null. I checked in the tree and all the content is published.
Afterwards I changed line to use Where and Select instead of OfType
Home home = Umbraco.ContentAtXPath("//home").Where(h => h is Home).Select(h => h as Home).First();
And noticed while the content is loaded, when it checks if it's of the given type it always returns false even if during debug mode it shows that the h variable in Where is of the type generated by ModelsBuilder.
I can't reproduce this in 8.2.2, so I don't think it's something that's changed between versions. Which mode do you have ModelsBuilder in? I assume that ModelsBuilder is regenerating the class at some stage, so although h is of a type called Umbraco.Web.PublishedModels.Home or whatever, it's not actually the same type as the controller was compiled with.
Can you compare typeof(Home).AssemblyQualifiedName and h.GetType().AssemblyQualifiedName?
ContentAtXPath type
Hi,
I'm making an API controller that is supposed to send content over requests.
On a project created in 8.1.5 I have no issues with accessing content of a specific type like this:
The 8.1.5 is a project I use for testing things out before moving to the commercial project.
However, if I try and do the exact line of code on the actual project (which is in 8.2.2) the Home (or whatever type) is just null. I checked in the tree and all the content is published.
Afterwards I changed line to use Where and Select instead of OfType
And noticed while the content is loaded, when it checks if it's of the given type it always returns false even if during debug mode it shows that the h variable in Where is of the type generated by ModelsBuilder.
Anyone that can help me with this issue?
I can't reproduce this in 8.2.2, so I don't think it's something that's changed between versions. Which mode do you have ModelsBuilder in? I assume that ModelsBuilder is regenerating the class at some stage, so although
h
is of a type calledUmbraco.Web.PublishedModels.Home
or whatever, it's not actually the same type as the controller was compiled with.Can you compare
typeof(Home).AssemblyQualifiedName
andh.GetType().AssemblyQualifiedName
?is working on a reply...