hi, I would like to ask how to serialize class with members like
SqlParameter. I try to use BinaryFormatter.
[Serializable]
public class Example_Class
public SqlParameter sqlParam;
public Example_Class()
sqlParam = new SqlParameter("@Data", SqlDbType.VarChar);
class App
[STAThread]
static void Main()
FileStream fs = new FileStream("DataFile.dat", FileMode.Create);
// Construct a BinaryFormatter and use it
// to serialize the data to the stream.
BinaryFormatter formatter = new
Example_Class dod = new Example_Class();
// Serialize the array elements.
formatter.Serialize(fs, dod);
// Deserialize the array elements.
fs.Position = 0;
Example_Class dod2 = (Example_Class) formatter.Deserialize(fs);
Console.WriteLine("Do both class refer to the same object? "
+ (dod.sqlParam == dod2.sqlParam));
Console.ReadLine();
catch (SerializationException e)
Console.WriteLine("Failed to serialize. Reason: " + e.Message);
Console.ReadLine();
throw;
finally
fs.Close();
and error is :
"The type System.Data.SqlClient.SqlParameter in Assembly System.Data,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 is
not marked as serializable."
but I know that's possible. What I do wrong ?
How do I have to implement this?
Thanks,
Marcin
This thread has been closed and replies have been disabled. Please start a new discussion.