public static void Serialize(Object dictionary, Stream stream) { try // try to serialize the collection to a file { using (stream) { // create BinaryFormatter BinaryFormatter bin = new BinaryFormatter(); // serialize the collection (EmployeeList1) to file (stream) bin.Serialize(stream, dictionary); } } catch (IOException) { } } public static Object Deserialize(Stream stream) where Object : new() { Object ret = CreateInstance(); try { using (stream) { // create BinaryFormatter BinaryFormatter bin = new BinaryFormatter(); // deserialize the collection (Employee) from file (stream) ret = (Object)bin.Deserialize(stream); } } catch (IOException) { } return ret; } // function to create instance of T public static Object CreateInstance() where Object : new() { return (Object)Activator.CreateInstance(typeof(Object)); } // Usage Serialize(userSessionLookupTable, File.Open("data.bin", FileMode.Create)); Dictionary deserializeObject = Deserialize>(File.Open("data.bin", FileMode.Open));