You can take a look at my answer here: System.NullReferenceException 'Object reference not set to an instance of an object.'.
Here is a short summary:
- When you have a statement like
A.B.C = E.F;
, and you receive an NullReferenceException 'Object reference not set to an instance of an object.' on that line of code, it basically means either A, or B or E are null. - To figure out what's wrong there, you can set a breakpoint on the same line, start debugging and then when the breakpoint hits, just check the value of A, B or E.
Learn more
For more information and examples, take a look at the following links:
- NullReferenceException remarks (Microsoft Learn)
- What is a NullReferenceException, and how do I fix it? (stackoverflow)
- Tutorial: Learn to debug C# code using Visual Studio