Following NullReferenceException throws when ChildFolders() gets called. In the bottom of the picture, one can see that at least one desired Folder exists. But trying to access them doesnt work. How does this happen?
Asked
Active
Viewed 101 times
-2
-
3Please provide an [mcve] – NineBerry Oct 23 '19 at 13:08
-
1You error is very clear. The folder is not instantiated – Bosco Oct 23 '19 at 13:10
-
1Your list of folders contains null. – NineBerry Oct 23 '19 at 13:10
-
How to ask a good question https://stackoverflow.com/help/how-to-ask – NineBerry Oct 23 '19 at 13:12
-
1Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – NineBerry Oct 23 '19 at 13:13
-
Please paste your code, and the type and message from exceptions, into your question as text. It's hardly convenient for us to squint at an enormous blacked-out screenshot with a small amount of relevant information scattered here and there. – 15ee8f99-57ff-4f92-890c-b56153 Oct 23 '19 at 13:13
1 Answers
-1
Just use the null-conditional operator
return Folders.FindAll(x => x?.ParentFolderID == parentFolderId);

Innat3
- 3,561
- 2
- 11
- 29