title: C# Can't Deserialize DataTable
body: <p>I have a client/server project and I'm trying to send via socket a DataTable(extracted from a TableAdapter) from server to client.
  My server namespace is srvCentral and my client is appClient.
  When I try to deserialize DataTable in client it throws me an Serialize Exception saying 
  Unable to find assembly 'srvCentral, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
  I've googled and tryed things like controlling the AssemblyResolve, that makes svchost hang and force me to close, and using a binder like this:</p>
  
  <pre><code>sealed class AllowAllAssemblyVersionsDeserializationBinder : SerializationBinder
  {
      public override Type BindToType(string assemblyName, string typeName)
      {
          Type typeToDeserialize = null;
  
          String currentAssembly = Assembly.GetExecutingAssembly().FullName;
  
          // In this case we are always using the current assembly
          assemblyName = currentAssembly;
  
          // Get the type using the typeName and assemblyName
          typeToDeserialize = Type.GetType(String.Format("{0}, {1}",
                                           typeName, assemblyName));
  
          return typeToDeserialize;
      }
  }
  </code></pre>
  
  <p>And the exception stills there...
  Wasn't it suppose to DataTable be Deserializable anywhere?
  What am I doing wrong?</p>
  
  <p>My Serialization code is:</p>
  
  <pre><code>public byte[] Serializar(Object item)
  {
      BinaryFormatter formatter = new BinaryFormatter();
      MemoryStream ms = new MemoryStream();
      formatter.Serialize(ms, item);
      return ms.ToArray();
  }
  
  public Object Deserializar(byte[] buffer)
  {
      BinaryFormatter formatter = new BinaryFormatter();
      MemoryStream ms = new MemoryStream(buffer);
  
      formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
  
      formatter.Binder = new AllowAllAssemblyVersionsDeserializationBinder();
  
      Object a = formatter.Deserialize(ms);
  
      return a;
  }
  
  sealed class AllowAllAssemblyVersionsDeserializationBinder : SerializationBinder
  {
      public override Type BindToType(string assemblyName, string typeName)
      {
          Type typeToDeserialize = null;
  
          String currentAssembly = Assembly.GetExecutingAssembly().FullName;
  
          // In this case we are always using the current assembly
          assemblyName = currentAssembly;
  
          // Get the type using the typeName and assemblyName
          typeToDeserialize = Type.GetType(String.Format("{0}, {1}",
                                           typeName, assemblyName));
  
          return typeToDeserialize;
      }
  }
  </code></pre>
  
  <p><strong>After some digging I've solve the problem with this;</strong></p>
  
  <p>It isn't the better way to solve it but is a easy way to avoid the problem. For small things it's enough. Use this if you want to retrieve data from table for show content only.</p>
  
  <pre><code>namespace YourLibrary
  {
  [Serializable]
  public class Tabela: ISerializable
  {
      protected ArrayList colNames;
      protected ArrayList colTypes;
      protected ArrayList dataRows;
  
      public Tabela()
      {
  
      }
  
      public Tabela (DataTable dt)
      {
          colNames = new ArrayList();
          colTypes = new ArrayList();
          dataRows = new ArrayList();
          // Insert column information (names and types)
          foreach(DataColumn col in dt.Columns)
          {
              colNames.Add(col.ColumnName); 
              colTypes.Add(col.DataType.FullName);   
          }
  
          // Insert rows information
          foreach(DataRow row in dt.Rows)
              dataRows.Add(row.ItemArray);
      }
  
      public Tabela(SerializationInfo info, StreamingContext context)
      {
          colNames = (ArrayList)info.GetValue("colNames",typeof(ArrayList));
          colTypes = (ArrayList)info.GetValue("colTypes",typeof(ArrayList));
          dataRows = (ArrayList)info.GetValue("dataRows",typeof(ArrayList));
  
      }
  
      void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
      {
          info.AddValue("colNames", colNames);
          info.AddValue("colTypes", colTypes);
          info.AddValue("dataRows", dataRows);
      }
  
      public DataTable GenerateDataTable()
      {
          DataTable dt = new DataTable();
  
          // Add columns
          for(int i=0; i&lt;colNames.Count; i++)
          {
              DataColumn col = new DataColumn(colNames[i].ToString(), 
                  Type.GetType(colTypes[i].ToString() ));     
              dt.Columns.Add(col);
          }
  
          // Add rows
          for(int i=0; i&lt;dataRows.Count; i++)
          {
              DataRow row = dt.NewRow();
              row.ItemArray = (object[]) dataRows[i];
              dt.Rows.Add(row);
          }
  
          dt.AcceptChanges();
          return dt;
      }
  }
  }
  </code></pre>