-1
        private List<InMemoryRandomAccessStream> undoStreamList;            
        InMemoryRandomAccessStream tempStream = new InMemoryRandomAccessStream();
        await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(tempStream);
        undoStreamList.Add(tempStream);
        state++;

This code returns a NullReferenceException on the penultimate line, how do I fix it?

I also tried changing the penultimate line to undoStreamList.Add(new InMemoryRandomAccessStream); but it didn't work.

1 Answers1

1

It looks like your list has not been initialized:

// Initialize this either inline or inside the constructor...
private List<InMemoryRandomAccessStream> undoStreamList = new List<InMemoryRandomAccessStream>();

InMemoryRandomAccessStream tempStream = new InMemoryRandomAccessStream();
await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(tempStream);
undoStreamList.Add(tempStream);
state++;

This is the only possible reason for that line throwing an exception!

Tommaso Belluzzo
  • 21,428
  • 7
  • 63
  • 89