If you are getting a null reference error on the line:
if (buffer1.Count != 0)
Then the only possible reason is that butter1 is null: i.e. you have not assigned a value to it anywhere. Try looking at all the references to it, and look for either places where you assign buffer1 (and the assigned value could be
null
) or for somewhere in the code where you should be writing something like:
buffer1 = new List<int>();
but aren't!