Search code examples
.netvb.netarraysbytebufferunmanaged-memory

Convert UnmanagedMemoryStream to Byte-Array


Simple as that, how I can convert in VBNET a UnmanagedMemoryStream to Byte-Array?:

Dim bytes() As Byte = My.Resources.AudioFile

Exception:

Value of type 'System.IO.UnmanagedMemoryStream' cannot be converted to '1-dimensional array of Byte'.

Solution

  • You can convert System.IO.MemoryStream directly to a Byte() Array, by using:

    Dim myMemStream As New System.IO.MemoryStream
    My.Resources.AudioFile.CopyTo(myMemStream)
    Dim myBytes() As Byte = myMemStream.ToArray