Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7408261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:52:59+00:00 2026-05-29T05:52:59+00:00

What are the possible causes for Stream not Writable Exception when serializing custom object

  • 0

What are the possible causes for Stream not Writable Exception when serializing custom object over TCP using Network Stream in C#.
I am Sending the Mp3 data in the form of Packets.The Frame consists of Byte[] Buffer.I am Using Binary Formatter to serialize the object.

BinaryFormatter.Serialize(NetworkStream,Packet);

The Mp3 Played at client with distortion and jitters end for few seconds and then The above mentioned exception raised.I m using NAudio Open Source library for it.

Before doing this modification I was using

NetworkStream.Write(Byte[] Buffer,0,EncodedSizeofMp3);
and it was writing it successfully before giving any exception

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:53:01+00:00Added an answer on May 29, 2026 at 5:53 am

    If you are writing to a NetworkStream, the stream/socket could be closed

    If you are writing to a NetworkStream, it could have been created with FileAccess.Read

    If I had to guess, though, it sounds like something is closing the stream – this can be the case if, say, a “writer” along the route assumes it owns the stream, so closes the stream prematurely. It is pretty common to have to write and use some kind of wrapper Stream that ignores Close() requests (I have one in front of me right now, in fact, since I’m writing some TCP code).

    As a small aside; I generally advise against BinaryFormatter for comms (except remoting) – most importantly: it doesn’t “version” in a very friendly way, but it also tends to be a bit verbose in most cases.

    Here’s the wrapper I’m using currently, in case it helps (the Reset() method spoofs resetting the position, so the caller can read a relative position):

    class NonClosingNonSeekableStream : Stream
    {
        public NonClosingNonSeekableStream(Stream tail)
        {
            if(tail == null) throw new ArgumentNullException("tail");
            this.tail = tail;
        }
    
        private long position;
        private readonly Stream tail;
        public override bool CanRead
        {
            get { return tail.CanRead; }
        }
        public override bool CanWrite
        {
            get { return tail.CanWrite; }
        }
        public override bool CanSeek
        {
            get { return false; }
        }
        public override bool CanTimeout
        {
            get { return false; }
        }
        public override long Position
        {
            get { return position; }
            set { throw new NotSupportedException(); }
        }
        public override void Flush()
        {
            tail.Flush();
        }
        public override void SetLength(long value)
        {
            throw new NotSupportedException();
        }
        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new NotSupportedException();
        }
        public override long Length
        {
            get { throw new NotSupportedException(); }
        }
        public override int Read(byte[] buffer, int offset, int count)
        {
            int read = tail.Read(buffer, offset, count);
            if (read > 0) position += read;
            return read;
        }
        public override void Write(byte[] buffer, int offset, int count)
        {
            tail.Write(buffer, offset, count);
            if (count > 0) position += count;
        }
        public override int ReadByte()
        {
            int result = tail.ReadByte();
            if (result >= 0) position++;
            return result;
        }
        public override void WriteByte(byte value)
        {
            tail.WriteByte(value);
            position++;
        }
        public void Reset()
        {
            position = 0;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What could be the possible causes for the following exception? System.PlatformNotSupportedException: 'ResourcePool' is not
In Java SE it is possible set the cause of an exception using initCause
I have an application in which I am sending network data over WiFI. Everything
What are the possible causes of premature redo log switching in Oracle other than
What might be the possible cause of the following? I am using an autocomplete
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
I am using SDL audio to play sounds. SDL_LockAudio tells this : Do not
It's not possible to set a connection timeout on a .NET remoting call. Documentation
I'm currently writing a custom video player using AVPlayer. The video plays fine and
Is it possible to distinct xs:choices in xsd by using fixed values? I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.