I'm trying to read the bytes from a file that I've retrieved from an external source, however when running the code I get the following error:
System.NotSupportedException: Specified method is not supported.\r\n at System.Net.Http.HttpBaseStream.get_Length()
My code in question is as follows:
var responseBody = (request.GetResponseAsync().Result).GetResponseStream();
byte[] file;
var br = new BinaryReader(responseBody);
file = br.ReadBytes((int)br.BaseStream.Length);
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = responseBody.Read(file, 0, file.Length)) > 0)
{
ms.Write(file, 0, read);
}
}
var result = new MemoryStream(file);
It fails on the following line:
file = br.ReadBytes((int)br.BaseStream.Length);
I can't seem to find a solution to the issue, can anyone suggest a fix?