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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:55:38+00:00 2026-06-01T11:55:38+00:00

I have 2 clases: public class products { public string category; public string name;

  • 0

I have 2 clases:

 public class products
{
    public string category;
    public string name;
    public double price;
    public string desc;
    public string version;
    public string logoURL;
    public string imgURL;
    public string prod;

    public string Category
    {
        set { categorie = value; }
        get { return category; }
    }

and:

    [Serializable()]
public  class groupProducts
{
    public products[] produse;
}

I want to XmlSerialize the groupProducts class and send the data from a server via TCP conection to a client!
I’ve tried something like:

   groupProducts gp = new groupProducts();
XmlSerializer xmlSel = new XmlSerializer(typeof(groupProducts));
TextWriter txtStream = new StreamWriter("xmlStreamFile.xml");    
xmlSel.Serialize(txtStream, gp); 
txtStream.Close();
try
{
Stream inputStream = File.OpenRead("xmlStreamFile.xml");
// declaring the size of the byte array to the length of the xmlfile
msg = new byte[inputStream.Length];
//storing the xml file in the byte array
inputStream.Read(msg, 0, (int)inputStream.Length);
//reading the byte array 
communicator[i].Send(msg);
}

but it when I Deserialize it on the client side – the XML file has some weird data in it!

Do you have any idea what could it be? What am I doing wrong?

  • 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-01T11:55:39+00:00Added an answer on June 1, 2026 at 11:55 am

    1- To be safe I would use an encoding while opening StreamWriter

    2- In inputStream.Read(msg, 0, (int)inputStream.Length); Read does’t guarantee that you will get inputStream.Length bytes from stream. You have to check the returned value.

    3- You don’t need a temp file. Use MemoryStream

    XmlSerializer xmlSel = new XmlSerializer(typeof(groupProducts));
    MemoryStream m = new MemoryStream();
    xmlSel.Serialize(m);
    communicator[i].Send(m.ToArray());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume i have a class: public class Products { public string ID { get;
I have a domain class like public class Category { [Key] public string IdCategory
Simple question on best practice. Say I have: public class Product { public string
I have this Class: public class User { public string id{ get; set; }
I have a class public class A<T> { public static string B(T obj) {
I have two entities in 1:n relationship: Category and Product. public class Category {
I have a class Category, that represents products category... So I created a View
I have a class: public class Data { public Ilist<Prod> Product; public Data() {}
Suppose I have public class Product: Entity { public IList<Item> Items { get; set;
I have a viewmodel that contains a product and SelectList of categories. public class

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.