Search code examples
webassemblyuno-platform

DataWriter.StoreAsync() not available on WASM


I am having an issue downloading images from my website with my Uno App on the WASM Platform.
It works against UWP. My code is:

StorageFile imageFile = await SelectedFolder.CreateFileAsync($"{item.picturekey}.jpg",
    Overwrite ? CreationCollisionOption.ReplaceExisting : CreationCollisionOption.FailIfExists);
if (imageFile != null)
{                        
    byte[] imageArray = await DataService.GetImage(item.picturekey, item.hiresurl);
    if (imageArray != null)
    {
        var stream = await imageFile.OpenAsync(FileAccessMode.ReadWrite);
        using (var outputStream = stream.GetOutputStreamAt(0))
        {
            using (DataWriter writer = new DataWriter(outputStream))
            {
                if (imageArray != null)
                {
                        sb.AppendLine(this.DownloadStatus);
                        await writer.StoreAsync();
                        await outputStream.FlushAsync();
                }
            }
        }
        stream.Dispose();
    }
}

When I test against wasm, I receive:

fail: Windows.Storage.Streams.DataWriter[0]
    The member DataWriter.DataWriter(IOutputStream outputStream) is not implemented in Uno.

My try-catch give me: System.NullReferenceException: Arg_NullReferenceException at Windows.Storage.Streams.DataWriter.WriteBytes[Byte[] value) ... line 62

I have checked to be sure, imageArray.Length > 0, so I am not passing in a null.

I assume that it is really supported in Uno for UWP and not WASM, is there a work-around?

Thanks, any suggestions would be helpful.


Solution

  • DataWriter is not implemented for streams at this point.

    You should be able to use .AsStreamForWrite() extension method and use a .NET StreamWriter instead.

    Uno Platform generally chooses to implement WinRT APIs based on the presence of an equivalent API in the .NET APIs, which is why some portions like this one are not yet available.