MemoryStream does not contain a definition for GetBuffer()

☆樱花仙子☆ 提交于 2019-12-11 05:55:53

问题


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

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' 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?)"

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.


回答1:


Rather than GetBuffer you need to use TryGetBuffer.

See https://github.com/dotnet/corefx/issues/1897 for more details.



来源:https://stackoverflow.com/questions/45282478/memorystream-does-not-contain-a-definition-for-getbuffer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!