Save Task<string> type to String giving Catastrophic failure

393 views Asked by At

I am trying to save the Ink I write on Canvas in a class and reload it with these two methods found at this link.

    private async Task<string> WriteInk() {
        using (var stream = new InMemoryRandomAccessStream()) {
            await inkManager.SaveAsync(stream);
            await stream.FlushAsync();
            stream.Seek(0);
            byte[] bytes = new byte[stream.Size];
            IBuffer buffer = bytes.AsBuffer();
            await stream.ReadAsync(buffer, (uint)stream.Size, InputStreamOptions.None);
            return Convert.ToBase64String(bytes);
        }
    }

    private async void ReadInk(string base64) {
        if (string.IsNullOrEmpty(base64)) return;
        var bytes = Convert.FromBase64String(base64);

        using (var stream = new InMemoryRandomAccessStream()) {
            await stream.WriteAsync(bytes.AsBuffer());
            await stream.FlushAsync();
            stream.Seek(0);

            await inkManager.LoadAsync(stream);

            if (inkManager.GetStrokes().Count > 0) {
                RenderInk();
            }
        }
    }

I have a class where I save the base64 returned from WriteInk():

    public class MyCanvas
    {
        public string canvasIndex { get; set; }
        public String canvasStrokes { get; set; }
    }

My problem is when calling WriteInk():

MyCanvas mc = new MyCanvas();
mc.canvasStrokes = await m_CanvasManager1.WriteInk();

I get an Exception: Catastrophic failure. + I can't make canvasStrokes of type string and save Task<string> to it + The method ReadInk() takes the base64 as a string

To what type should I save Task<string> to be able to use it as string in the second method?

When I call WriteInk, it arrives to await inkCanvas.SaveAsync(stream); it returns to where it was called at mc.canvasStrokes = await m_CanvasManager0.WriteInk();and give this exception:

An exception of type 'System.Exception' occurred in mscorlib.dll but was not handled in user code. Additional information: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

0

There are 0 answers