You don't need to set the MemoryStream position to get the byte array. That line can be removed.
Don't use memoryStream.Position = 0. The correct way is:
memoryStream.Position = 0
// set Position at the beginning of the stream memoryStream.Seek(0, SeekOrigin.Begin);