You are showing unrelated code. No, don't show any code right now, you don't really understand what your own code does. You sample is unrelated, because the exception is in
And you did not show any code around this call shown in your stack trace. You see, you exception is one of the easiest to fix. Run it under debugger. To start with, locate your call to the method shown above and put a breakpoint on this line. Try to run. Before the call, look at the members and variables involved. At least one of them is null but is not supposed to be null. Inspect all relevant value under debugger before a call and find out the bug. Apply this approach to other cases. Fix the bug: either make sure the problematic reference variable or member is initialized with a non-null reference (constructor called or your reference is assigned to some already initialized variable), or, if appropriate, make a conditional statement: check a variable or a member in question for null and don't the operation where it is used if it is null.