MemoryStream does not contain a definition for Get

2019-08-07 03:47发布

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条回答
小情绪 Triste *
2楼-- · 2019-08-07 04:22

Rather than GetBuffer you need to use TryGetBuffer.

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

查看更多
登录 后发表回答