I got this error
ReadTimeout = \'((System.IO.Stream)(ms)).ReadTimeout\' threw an exception of type \'System.InvalidOperationException\'.
M
You should be careful about the type of image in database, if your image is too big then you must use LONGBLOB and not BLOB.
I used the following code and I needed the MemoryStream to be used as email attachment:
string filename=@"C:\images\myimage.img"
MemoryStream result = new MemoryStream();
MemoryStream source = new MemoryStream(File.ReadAllBytes(filename));
source.WriteTo(result);
The ReadTimeout
property must be overridden, in the base System.IO.Stream
class it always throw System.InvalidOperationException
error by design.
The solution is not to cast ms
to the base type when reading the timeout:
int readTimeout = ms.ReadTimeout;
Edit: didn't check before posting.. MemoryStream also does not override that property - meaning timeout for such stream is not implemented.
You have to either use other implementation of Stream class that does override the ReadTimeout
property, or write your own implementation.
You can use the ReadTimeout/WriteTimeout properties only if the stream support timing out. You can check this via the CanTimeout property. If the CanTimeout property returns false all access to these properties should raise an InvalidOperationException.