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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:08:20+00:00 2026-06-12T13:08:20+00:00

Hey guys I’m making a chat program and I have a parent MessagePacket class

  • 0

Hey guys I’m making a chat program and I have a parent “MessagePacket” class with a bunch of child classes for different types of packets to be sent, either containing a message for the main chat window, list of people currently chatting, private chat message, etc.

In the client the first thing I do is create a “AddClientPacket” and serialize/send it to the server, the server then deserializes it as its parent “MessagePacket” class which contains a type property that is used to determine what to cast/do with the generic MessagePacket it got.

When the server trys to deserialize it it causes a crash, im not sure why. Heres some code:

–SERVER–

    private void HandleClientComm(Object client)
    {
        Client addClient = new Client(clientIds++, ((TcpClient)client).GetStream());

        IFormatter formatter = new BinaryFormatter();


        while (true)
        {
            MessagePacket packet = new MessagePacket();

            try
            {
                packet = (MessagePacket)formatter.Deserialize(addClient.ClientStream);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }



            switch (packet.Type)
            {
                case MessageType.ALLCHAT:
                    {
                        messages.Enqueue(((AllChatPacket)packet).Message);
                    }
                break;
                case MessageType.ADDCLIENT:
                    {

                        addClient.ClientName = ((AddClientPacket)packet).ClientName;
                        clientNames.Add(addClient.ClientName);
                        clientList.Add(addClient);
                    }
                break;
                case MessageType.REMOVECLIENT:
                   {
                       clientNames.Remove(addClient.ClientName);
                       clientList.Remove(addClient);
                   }
                   break;
                case MessageType.PRIVATECHAT:
                   {

                   }
                   break;
            }
        }
    }

–CLIENT–

    public void ListenToServer()
    {
        AddClientPacket addClient = new AddClientPacket();
        addClient.Type = MessageType.ADDCLIENT;


        name = addClient.ClientName = Interaction.InputBox("Whats your name", "Name?", "", 100, 100);

        try
        {
            formatter.Serialize(clientStream, addClient);
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
            this.Close();
            return;
        }


        while (true)
        {
            if (quit)
            {
                break;
            }

            MessagePacket packet = new MessagePacket();

            try
            {
                packet = (MessagePacket)formatter.Deserialize(clientStream);
            }
            catch (Exception)
            {
                return;
            }

            switch (packet.Type)
            {
                case MessageType.ALLCHAT:
                    {
                        textBox1.Text = textBox1.Text + Environment.NewLine + ((AllChatPacket)packet).Message;
                        textBox1.Refresh();
                    }
                    break;
                case MessageType.NAMELIST:
                    {
                        clientNameList.DataSource = ((NameListPacket)packet).ClientNames;
                    }
                    break;
            }
        }
    }
  • 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-12T13:08:21+00:00Added an answer on June 12, 2026 at 1:08 pm

    That would be the issue then. Even though they ‘look’ the same to you, have the same properties, .NET sees them as completely different types if they are defined in two different assemblies and therefore will not let you serialize TypeA and deserialize it into TypeB. You are going to have to create a single .dll with that class definition that both share.

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

Sidebar

Related Questions

Hey guys I am making a 2D game and I have generating a random
Hey guys this is my html code: <div class=nakupy> <li class=icn_kategorie><a href=#>Nákupy</a> <div class=sub_menu>
hey guys having this really simple problem but cant seem to figure out have
Hey guys I have a object sitting in my tile map for spawn point
Hey guys am having a bit of problems with my jQuery, I have all
Hey guys I have an array of dictionaries plist file that I am reading
Hey guys here is my question. im using JCombobox. if a student have CB
Hey guys I am making a terminal application using Swing and Apache Commons. I
Hey guys I am new to android development, I am currently making an application.The
hey guys should be a easy one...I have some javascript that is turning my

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.