在將對象序列化的時(shí)候,本地測試沒問題。在iis6下就出現(xiàn)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; }??????? }
3 回答

函數(shù)式編程
TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個(gè)贊
filestream = new FileStream("ProduceCheck.files", FileMode.Create);
這里創(chuàng)建 FileStream 的時(shí)候拋出了異常,
你把異常吃掉了,
catch (Exception ex)?
{
??????throw ex; // 這里出現(xiàn)的異常會告訴你你無權(quán)縣創(chuàng)建FileStream,或者??ProduceCheck.files 已存在等錯(cuò)誤.
}
所以,異常會從這里拋出,因?yàn)?filestream == null,系統(tǒng)報(bào)告 NullReferenceException.
finally
{
??????????????? filestream.Close();
}
- 3 回答
- 0 關(guān)注
- 1166 瀏覽
添加回答
舉報(bào)
0/150
提交
取消