Stream does not support writing exception

Dec 29, 2009 at 12:43 PM


I just downloaded and tried to run the sample application. However, I get a NotSupportedException, "Stream does not support writing exception" in SeekableStream.cs , line 127:  base.Write(_asyncStreamBuffer, 0, contentReadTotal);

Any ideas?

Dec 29, 2009 at 6:56 PM


I wrote the SeekableStream to be read-only for the purposes of downloading Media content only.

And as well, the method in which I implemented it does not work for Writeable streams. It uses a MemoryStream internally which is asynchronously filled.

If you wanted to write to SeekableStream then, it will be writing to the internal MemoryStream and this would break the abstraction since all derived Stream classes are readable but not all are writeable, such as Microsoft's Internal NetworkStream which is what HttpWebRequest uses internally.

There are a few restrictions with Microsoft's internal network stream, the major one being that it is not seekable.

Thinking about it, I should actually make it Writeable because if the underlying stream (the one passed into the SeekableStream constructor) does not support Write, then the same Exception will be thrown. I will look into this but it also means that I have to test it with a few other Stream types to make sure it is robust.

I'll update any developments here specific to this issue.


Jan 5, 2010 at 4:02 PM


Thanks for your reply.

But I don't understand. I downloaded the solution and just ran it by pressing F5. I didn't change anything, and it crashes right away without my doing anything.

Oh well... I will have to look somewhere else for a Silverlight streaming solution.



Jan 5, 2010 at 7:48 PM

After some prelimanary testing, I've decided not to make the SeekableStream writeable.

It incurs a sizeable overhead for what it was intended to be, that is, a readable seekable stream.

Instead of giving up on the project, you should have posted the errors you are encountering so that I could have tried to fix it and make the fix available to others.

Oh well, good luck with your search.

Jan 6, 2010 at 8:21 AM


Thanks for your reply.

I did post the error in my first message.

However, for full details, here is the complete error message:

System.NotSupportedException was unhandled by user code
  Message="Stream does not support writing."
       at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at Saluse.MediaKit.IO.SeekableStream.FillMemoryStreamFromSourceStream(Object state)
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart(Object obj)

It occurs at method base.Write(_asyncStreamBuffer, 0, contentReadTotal); , line 127 in SeekableStream.cs


Jan 6, 2010 at 7:36 PM

When you load the solution (VS2008 or VS2010?), is "Saluse.MediaKit.Sample.Web" the startup project and "Saluse.MediaKit.SampleTestPage" the startup page?


Jan 7, 2010 at 8:03 AM



"Saluse.MediaKit.Sample.Web 2008" is the startup project and "Saluse.MediaKit.SampleTestPage.aspx" is the startup page.

However, I just found out that this error is only thrown on a Windows XP box. On a Windows 7 box, it seems to be working fine.



Feb 13, 2010 at 3:18 PM

@MagnusJ - I only get this error when I run it on a computer that has the SL4 beta run-time installed. Do you think that is also the reason you got the error?


Feb 20, 2010 at 6:28 PM


For the two methods to replace in SeekableStream.cs to resolve this issue in Silverlight 4.