The following code will always throw UnuthorizedAccessException (MemoryStream\'s internal buffer cannot be accessed.)
byte[] buf1 = { 2, 3, 5, 7, 11 }; var
You appear to be using MemoryStream(array[]) which does not match any of the three versions mentioned in the docs.
MemoryStream(array[])