0

Additional information: Type 'System.Windows.Forms.ListBox+ObjectCollection' in Assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

[Serializable]
public class User_List
{    
   public ListBox.ObjectCollection users;
}


// Getting the Data Ready
else if (temp is BPacket.Credentials)
{
   BPacket.Credentials U = (BPacket.Credentials)temp;
   OnlineUsers.Items.Add(loc.ToString() + " " + U.UserName);
   AllUsers[loc].UserName = U.UserName;

   BPacket.User_List UL = new BPacket.User_List();   
   UL.users = OnlineUsers.Items;

   SendOutData(UL);    
}

private void SendOutData(object temp)
{
   if (temp is BPacket.User_List)
   {
      for (int x = 0; x < NextLocation; x++)
      {
         formatter.Serialize(AllUsers[x].ConnStream, temp);  // send data //This is where the exception is thrown
      }

   }

} //END SendOutData

So I want to know how to make my User_List serializable.

dbc
  • 104,963
  • 20
  • 228
  • 340
CalcGuy
  • 169
  • 1
  • 1
  • 10
  • Assuming `formatter` is `BinaryFormatter`, I don't think you can do this. Even if you use a serialization surrogate or wrapper along the lines of [How to serialize a Class contains BitmapImage?](https://stackoverflow.com/questions/29396771) and actually serialize an `object []`, [`ListBox.ObjectCollection`](https://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.objectcollection.aspx) doesn't have a parameterless constructor. It requires to know its `ListBox`. But `ListBox` isn't serializable, and not easily made so. Suggest you change your class to have an `object []` instead. – dbc Apr 30 '16 at 16:17
  • Yes it is a BinaryFormatter, but i ended up just using an array of strings to accomplish what i wanted. – CalcGuy Apr 30 '16 at 21:20

0 Answers0