在将对象序列化的时候,本地测试没问题。在iis6下就出现Object reference not set to an instance of an object. 请大虾们帮忙看看.
代码如下:
protected void btnsubmit_Click(object sender, EventArgs e)
{
Jisuangongshi jisuangongs = new Jisuangongshi();
jisuangongs.Zbgs = txtzb.Text;
jisuangongs.Djgs = txtdj.Text;
jisuangongs.Jbgs = txtjb.Text;
save(jisuangongs);
}
public void save(Jisuangongshi lstjsuan)
{
FileStream filestream = null;
try
{
filestream = new FileStream("ProduceCheck.files", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(filestream, lstjsuan);
}
catch (Exception ex)
{
}
finally
{
filestream.Close();
}
Response.Write("<script>alert('修改成功!');window.location.href='ParaManager.aspx';</script>");
}
[Serializable]
public class Jisuangongshi
{
private string _djgs;
public string Djgs
{
get { return _djgs; }
set { _djgs = value; }
}
private string _zbgs;
public string Zbgs
{
get { return _zbgs; }
set { _zbgs = value; }
}
private string _jbgs;
public string Jbgs
{
get { return _jbgs; }
set { _jbgs = value; }
}
filestream = new FileStream("ProduceCheck.files", FileMode.Create);
这里创建 FileStream 的时候抛出了异常,
你把异常吃掉了,
catch (Exception ex)
{
throw ex; // 这里出现的异常会告诉你你无权县创建FileStream,或者 ProduceCheck.files 已存在等错误.
}
所以,异常会从这里抛出,因为 filestream == null,系统报告 NullReferenceException.
finally
{
filestream.Close();
}
至少说明哪一行报的错啊
遇到过一种情况是dll 和aspx页面不匹配造成的