Stream.Length throws NotSupportedException

Viewed 53596

I am getting a error when attempting stream.Length on a Stream object sent into my WCF method.

Unhandled Exception!
 Error ID: 0
 Error Code: Unknown
 Is Warning: False
 Type: System.NotSupportedException
 Stack:    at System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream.get_Length()

How do you get the length of the stream? any examples?

7 Answers

I copied the stream into new stream and it worked for me.

Stream stream = new MemoryStream();
await streamthatcausingerror.CopyToAsync(stream); 

Related