MemoryStream不包含GetBuffer()的定义 [英] MemoryStream does not contain a definition for GetBuffer()
问题描述
我已经开始使用C#和.NET Core,并且正在尝试在 https:/ /stackoverflow.com/a/23739932/1459684
I've started working with C# and .NET Core and I'm trying to implement the code in the answer at https://stackoverflow.com/a/23739932/1459684
不过,我在
writer行中遇到问题。 (innerStream.GetBuffer(),0,length);
和
var base64 = Convert.ToBase64String(stream.GetBuffer(),0,( int)stream.Length).ToCharArray();
,其中方法 getBuffer()
似乎不再可用。我收到错误:
However, I have a problem with lines
writer.Write(innerStream.GetBuffer(), 0, length);
and
var base64 = Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length).ToCharArray();
where the method getBuffer()
no longer appears to be available. I receive the error:
'MemoryStream'不包含'GetBuffer'的定义,也没有扩展方法'GetBuffer'接受第一个可以找到类型为'MemoryStream'的参数(您是否缺少using指令或程序集引用?)
"'MemoryStream' does not contain a definition for 'GetBuffer' and no extension method 'GetBuffer' accepting a first argument of type 'MemoryStream' could be found (are you missing a using directive or an assembly reference?)"
使用Google仅此情况的其他实例似乎位于 https://github.com/hultqvist/ProtoBuf/issues / 35 ,但没有说明应该进行哪些重构。
With a Google the only other instance of this seems to be at https://github.com/hultqvist/ProtoBuf/issues/35 but does not give me an indication of what refactoring I should make.
推荐答案
而不是 GetBuffer
,您需要使用 TryGetBuffer
。
Rather than GetBuffer
you need to use TryGetBuffer
.
请参见 https://github.com/dotnet/corefx/issues/1897 更多详细信息。
这篇关于MemoryStream不包含GetBuffer()的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!