C# 为什么我会得到';系统数组';不包含';AsBuffer&x27&引用;用这个WinRT代码?

C# 为什么我会得到';系统数组';不包含';AsBuffer&x27&引用;用这个WinRT代码?,c#,windows-runtime,bytearray,bitmapimage,system.array,C#,Windows Runtime,Bytearray,Bitmapimage,System.array,根据,以下代码可用于将字节数组转换为位图图像: public static async Task<BitmapImage> ByteArrayToBitmapImage(this byte[] byteArray) { if (byteArray != null) { using (var stream = new InMemoryRandomAccessStream()) { await stream.Writ

根据,以下代码可用于将字节数组转换为位图图像:

public static async Task<BitmapImage> ByteArrayToBitmapImage(this byte[] byteArray)
{
    if (byteArray != null)
    {
        using (var stream = new InMemoryRandomAccessStream())
        {
            await stream.WriteAsync(byteArray.AsBuffer());
            var image = new BitmapImage();
            stream.Seek(0);
            image.SetSource(stream);
            return image;
        }
    }
    return null;
}
公共静态异步任务ByteArrayToBitmapImage(此字节[]byteArray)
{
if(byteArray!=null)
{
使用(var stream=new InMemoryRandomAccessStream())
{
wait stream.WriteAsync(byteArray.AsBuffer());
var image=新的位图图像();
stream.Seek(0);
image.SetSource(流);
返回图像;
}
}
返回null;
}
但是,我得到,“'System.Array'不包含'AsBuffer'的定义,并且找不到接受'System.Array'类型的第一个参数的扩展方法'AsBuffer'(是否缺少using指令或程序集引用?)

是不是“var流”赋值太模糊(隐式类型),我需要为“stream”var指定特定的数据类型?不是系统数组吗

也许这是一个线索: 缓冲区/字节数组-System.Runtime.InteropServices.WindowsRuntime。WindowsRuntimeBufferExtensions:此类中的扩展方法提供了在.NET字节数组和WinRT缓冲区内容之间移动的方法,这些缓冲区作为IBuffer实现公开


…但如果是的话,这还不足以让我知道如何处理它。它不是“TMI”,而是“NEI”(信息不足)。

问题是编译器找不到。确保有对命名空间
System.Runtime.InteropServices.WindowsRuntime
的引用,即

using System.Runtime.InteropServices.WindowsRuntime;
如果您还没有:

命名空间:System.Runtime.InteropServices.WindowsRuntime

程序集:System.Runtime.WindowsRuntime(在System.Runtime.WindowsRuntime.dll中)


我试图添加引用,但收到错误消息,无法添加该引用,因为它已被生成系统自动引用。因此,我添加了using语句并进行编译。因此,我想知道,如果需要的参考已经存在,为什么VS不知道,并给我一个“解决”上下文菜单项?不管怎么说,一切都很好,我想结局很好-谢谢!