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

  • Home
  • SEARCH
  • 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 981099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:29:18+00:00 2026-05-16T04:29:18+00:00

I am created a post before Object to byte not working . I fixed

  • 0

I am created a post before ” Object to byte not working ” .
I fixed problems that users said me , but there is still problem .

Error Message : The constructor to deserialize an object of type ‘WindowsFormsApplication1.Form1+Item’ was not found.;

void start()
{

 Item item = new Item();
 item.files.Add(@"test");
 byte[] b = ObjectToByteArray(item);  
     Item k = Desriles(b);

}


[Serializable]
public class Item : ISerializable
{
    public Item()
    {
        files = new List<string>();
        Exclude = false;
        CleanEmptyFolder = false;
    }
    public List<string> files;
    public string MusicProfileName;
    public bool Exclude;

    #region ISerializable Members

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        info.AddValue("files", files);
        info.AddValue("MusicProfileName", MusicProfileName);
        info.AddValue("Exclude", Exclude);
    }

    #endregion
}

public byte[] ObjectToByteArray(object _Object)
{
    using (var stream = new MemoryStream())
    {
        // serialize object 
        var formatter = new BinaryFormatter();
        formatter.Serialize(stream, _Object);

        // get a byte array
        var bytes = new byte[stream.Length];
        using (BinaryReader br = new BinaryReader(stream))
        {
            bytes = br.ReadBytes(Convert.ToInt32(stream.Length));
        }

        return bytes;
    }

}


    public Item Desriles(byte[] items)
    {
        using (MemoryStream stream = new MemoryStream())
        {

            stream.SetLength(items.LongLength);
            stream.write(items, 0, items.Length);
            var formatter = new BinaryFormatter();
            stream.Seek(0, SeekOrigin.Begin);

            object item = formatter.Deserialize(stream); // Here I will get error
            return (Item)item;


        }
    }
  • 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-16T04:29:19+00:00Added an answer on May 16, 2026 at 4:29 am

    The serialization code can’t work properly, you forgot to reset the stream back to the beginning. The better mouse trap:

        public byte[] ObjectToByteArray(object _Object) {
            using (var stream = new MemoryStream()) {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, _Object);
                return stream.ToArray();
            }
        }
    

    The deserialization code can similarly be simplified:

        public Item Desriles(byte[] items) {
            using (MemoryStream stream = new MemoryStream(items)) {
                var formatter = new BinaryFormatter();
                return (Item)formatter.Deserialize(stream);
            }
        }
    

    And you don’t need GetObjectData().

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

Sidebar

Related Questions

Is there a way to pass a newly created object(not saved yet) to another
I have created a Webpage which will post as post method..not as get method.
I have created a page on my site where users can post directly to
I have created objects that are interfaces to a web service. One typical object
Earlier I created an AddClient page that (when posted) passed a client object and
I have created a custom post type named People. I have created a page
i have created a custom post type named Books & i have a widget
I created a WebRequest to POST information. My objective is to emulate in C#
I created a NSEvent and I want to post it. How can I do
This post will be heavy on images. I have created a custom ArrayAdapter and

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.