GetRelatedDocuments null reference exception when using Page Type generated code

Ben Murphy asked on October 3, 2019 16:03

When I am using the generated classes to retrieve data from my pages, I am getting a null reference exception when try to receive an IEnumerable<TreeNode> for a 'Pages' form control.

Image Text

After debugging, mInstance is not null so I am unsure what is going wrong?

Recent Answers


David te Kloese answered on October 3, 2019 16:11

According to docs "This method returns an empty collection if the specified field does not exist or there are no associated related pages."

So it must be deeper... Does the relationship named in the field "RelatedPosts" exsist? Is any of the related items not published or removed?

0 votesVote for this answer Mark as a Correct answer

Ben Murphy answered on October 3, 2019 16:35 (last edited on October 3, 2019 16:35)

Yeah I saw that it should be returning an empty collection and thought that something funky is going on.

Here are screenshots of my field and contents Image Text

Image Text

Is this what you mean by does the relationship exist?

Many thanks

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on October 3, 2019 16:39

If I understood correctly you need to specify the Relationship NAME!

So you need to store the codename of the relationship in "RelatedPosts" field. Probably "isrelatedto" (default)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.