【问题标题】:DataWriter.StoreAsync() not available on WASMDataWriter.StoreAsync() 在 WASM 上不可用
【发布时间】:2021-09-30 17:11:01
【问题描述】:

我在 WASM 平台上使用我的 Uno 应用程序从我的网站下载图像时遇到问题。
它适用于 UWP。我的代码是:

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();
    }
}

当我针对 wasm 进行测试时,我收到:

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

我的 try-catch 给了我: System.NullReferenceException: Arg_NullReferenceException at Windows.Storage.Streams.DataWriter.WriteBytes[Byte[] value) ... 第 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.

【问题讨论】:

    标签: webassembly uno-platform


    【解决方案1】:

    DataWriter is not implemented 用于此时的流。

    您应该能够使用 .AsStreamForWrite() extension method 并使用 .NET StreamWriter instead

    Uno 平台通常会根据 .NET API 中等效 API 的存在来选择实现 WinRT API,这就是为什么像这样的某些部分尚不可用的原因。

    【讨论】:

      猜你喜欢
      • 2014-02-17
      • 2020-05-19
      • 2020-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多