Why dont you have the function declared like:
Public Function GetJpgImage(ByVal ImageID As Integer) as MemoryStream
if you are returning:
Return MyMemoryStream
EDIT: Try changing the return statement out of the using, Just for testing. It doesn't really matter if you include your return inside the using statement but just to be sure. Because the behaviour you are experiencing is not normal as well
Using MyResponseStream As IO.Stream = FTPResponse.GetResponseStream
'copy to memory stream so we can close the FTP connection
MyResponseStream.CopyTo(MyMemoryStream) '<== Why God? Why?
'close FTP stream
MyResponseStream.Close()
'gimme my data!
End Using
Return MyMemoryStream
EDIT2:. If you dont want to use the Copy To, try to read the stream into the memoryStream using the traditional way:
MemoryStream memStream;
using (Stream response = request.GetResponseStream()) {
memStream = new MemoryStream();
byte[] buffer = new byte[1024];
int byteCount;
do {
byteCount = stream.Read(buffer, 0, buffer.Length);
memStream.Write(buffer, 0, byteCount);
} while (byteCount > 0);
}