Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nikola 2 posts 72 karma points
    Nov 12, 2019 @ 11:58
    Nikola
    0

    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:

    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.

    Anyone that can help me with this issue?

  • Steve Megson 151 posts 1022 karma points MVP c-trib
    Nov 12, 2019 @ 16:48
    Steve Megson
    0

    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?

Please Sign in or register to post replies

Write your reply to:

Draft