1

I have a problem from send myObject by TCP/IP.

My ArchMap

public class ArchMap
{
    public string DetalCode { get; set; }
    public List<Arch> Archs { get; set; }
}

and Arch

public class Arch
{
    public string ModulName { get; set; }
    public string PartName1 { get; set; }
    [...]
}

I want to send this list to TcpClient but I don't know how convert my list to byte[].

I try

   var bf = new BinaryFormatter();
   var ms = new MemoryStream();
   bf.Serialize(ms, xarchList);

but I get error:

Additional information: Typ 'Arch_Sender.Model.ArchMap' in Assembly 'ArchSender.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
18666
  • 125
  • 1
  • 18

1 Answers1

1

Please consider using Serializable attribute like this:

ArchMap

using using System.Runtime.Serialization;

[Serializable]
public class ArchMap
{
    public string DetalCode { get; set; }
    public List<Arch> Archs { get; set; }
}

Arch

using System.Runtime.Serialization;

[Serializable]
public class Arch
{
    public string ModulName { get; set; }
    public string PartName1 { get; set; }
    [...]
}

More info: https://msdn.microsoft.com/en-us/library/ms973893.aspx

Fka
  • 6,044
  • 5
  • 42
  • 60