问一下序列化和反序列化的问题,实在是没办法了
我有两个类users和member,member是users的子类,我现在对users类进行序列化后存入数据库,但是我进行反序列化的时候抛出的错误是member是null
[Serializable]
public class Users
{
public string about;
public Member member = new Member();
}
[Serializable]
public class Member
{
public string name;
public string style;
}
private static void RunAll()//这是把序列化的结果存进数据库
{
string str = "hfsjdhfkdsfkdhfsdhfsfsdfsdfsdfsdfsdfdsfdsfdsfdfjsjfsjlajflajsijfaladskfj ";
string name = "艰苦的就 ";
string style = "11111111111111122222222222222222进风口大接访大开放 ";
Users users = new Users();
users.about = str;
users.member.name = name;
users.member.style = style;
BinaryFormatter f = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
f.Serialize(stream, users);
byte[] writeIn = new byte[stream.Length];
stream.Read(writeIn, 0, (int)stream.Length);
string strConn = ConfigurationSettings.AppSettings[ "ConnectionString "].ToString();
SqlCommand sqlCommand = new SqlCommand( "testser ", new SqlConnection(strConn));
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.Add(new SqlParameter( "@about ", SqlDbType.Image));
sqlCommand.Parameters[ "@about "].Value = writeIn;