I'm working on a recursive method that displays all documents I have permissions to see. The first pass works great, but when it calls itself recursively passing a document array of the current document's children it throws an error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during
the execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Have you checked to see if theres actually any documents in the childDocs array? Alternatively, if that's the case, you should be able to get the child documents like this: doc.Children;
/ Bo
Edit: Having a look at your code again, I think it will be good practice to "control" recursive methods with a few parameters. In this case, which node will be the start node? And when you meet a node with children, will that node be the new start node? When there is finally no more child collections, which node did you come from at the first place? Etc etc :-)
Maybe it would be better to refactor the code and make a helper method that iterates through childcollections? After all, everything that could be done recursively, can also be done with seperate iterations ;-) Just a thought..
Thanks for the reply. I built a workaround that passed the ID of the current node instead of the array of nodes. This seems to work better, though I'm not 100% sure why. Regardless, it got the job done. Thanks for your followup!
Object Error when dealing with Documents in API
I'm working on a recursive method that displays all documents I have permissions to see. The first pass works great, but when it calls itself recursively passing a document array of the current document's children it throws an error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Here's the code:
Hi Chris,
Is this still buggin' you? :-)
Have you checked to see if theres actually any documents in the childDocs array? Alternatively, if that's the case, you should be able to get the child documents like this: doc.Children;
/ Bo
Edit: Having a look at your code again, I think it will be good practice to "control" recursive methods with a few parameters. In this case, which node will be the start node? And when you meet a node with children, will that node be the new start node? When there is finally no more child collections, which node did you come from at the first place? Etc etc :-)
Maybe it would be better to refactor the code and make a helper method that iterates through childcollections? After all, everything that could be done recursively, can also be done with seperate iterations ;-) Just a thought..
Hi Bo,
Thanks for the reply. I built a workaround that passed the ID of the current node instead of the array of nodes. This seems to work better, though I'm not 100% sure why. Regardless, it got the job done. Thanks for your followup!
is working on a reply...