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 7851277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:07:57+00:00 2026-06-02T19:07:57+00:00

I want to deserialize a stream of bytes in a byte[] array in C#.

  • 0

I want to deserialize a stream of bytes in a byte[] array in C#. The byte[] array is 8196 bytes long and gets its information from a TCP/IP connection.

When I give that array to the ReadObject method of System.Runtime.Serialization.Json.DataContractJsonSerializer, it throws me a SerializationException with the message “Encountered unexpected character ‘\0′”.

How could I fix this?

  • 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-06-02T19:08:00+00:00Added an answer on June 2, 2026 at 7:08 pm

    How are you reading the string? Generally, the ‘\0’ error points to an encoding problem. The byte stream could use a particular type of encoding, and you’re either to force an encoding of your own — or you’re deserializing in such a way that a particular encoding inconsistent with the actual encoding of the stream is being assumed.

    http://social.msdn.microsoft.com/Forums/en/wcf/thread/b80c9aa7-a3d1-4aa0-b61a-35363cbc177e describes a situation where the replacement of the following line of code:

    s = ASCIIEncoding.Default.GetString(ms.GetBuffer());
    

    with:

            ms.Seek(0, SeekOrigin.Begin);
            StreamReader sr = new StreamReader(ms);
            s = sr.ReadToEnd();
    

    fixed the problem. Perhaps something similar applies to your situation as well?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to serialize/deserialize obj in/from byte[] on compact framework but there is no
Using c#, I want to deserialize xml from various sources into objects of a
I have JSON response from Facebook, which I don't want to deserialize into a
Want to send the text from my current vb application to the Active Window
want to fetch the value from dynamically created textfield with tag from NSMutableArray.... Txt_New_Estimated
I want to serialize a 'Player' class and send it over my network stream
the server throws this error Attempting to deserialize an empty stream at server side
I have a list of objects and I want to sent it thought TCP
We have an application where we need to de-serialize some data from one stream
I want to deserialize a XML file in C# (.net 2.0). The structure of

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.