问题如下:
未处理的“System.Runtime.Serialization.SerializationException”类型的异常出现在 未知模块 中。其他信息: 程序集 System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 中的类型 System.Web.HttpException 未标记为可序列化。我在Application_start()里面用这个类创建了一个对象结果出错了
代码如下using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Runtime.Serialization;
using System.Threading;
using System.Net; 
using System.IO;
using System.Text; 
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;namespace weather
{
/// <summary>
/// Timer 的摘要说明。
/// 程序书写:翔工作室技术副站长 傅昌铕(fuchangyou/Monster)(电脑男孩)(dnboy)
/// </summary>
public class Timer: System.Web.UI.Page
{
private Thread trd;
private static bool canRun;
public Timer()
{
//
// TODO: 在此处添加构造函数逻辑
//
canRun=true;
ThreadStart start=new ThreadStart(this.myRun);
trd=new Thread(start);
trd.IsBackground=true;
trd.Start();
}
protected void myRun()
{
//
//try
//{
while(canRun)
{
//try
//{//天气预报
this.getWeather();
//}
//catch
//{
//}
Thread.Sleep(900000);//自动取数据时间间隔为15分钟
}
//}
//catch{}
}
public Timer(string str)
{
try
{
trd.Abort();//关闭线程
}
catch
{
}
}
protected void getWeather()
{
//try
//{
//WebRequest wrq=WebRequest.Create("http://www.weathercn.com/forecastn/forcast/forecast_Detail_new.jsp?station_id=58027");

WebRequest wrq=WebRequest.Create("http://www.t7online.com/cgi-bin/citybild?SID=5802733961dea0bb14fd38888807f22bdf9e1&WMO=58027&LANG=cn");
HttpWebResponse wresp=(HttpWebResponse)wrq.GetResponse();
Stream s=(Stream)wresp.GetResponseStream();
StreamReader sr=new StreamReader(s,Encoding.Default);
FileStream fs=new FileStream(Request.PhysicalApplicationPath+"\\XmlData\\weather.xml",FileMode.Create,FileAccess.ReadWrite);
StreamWriter sw=new StreamWriter(fs,Encoding.UTF8);
string fss="";
sw.WriteLine(fss);
string html="",AllWeather="";
html=sr.ReadToEnd();
if(html==null||html=="")
return;
int start,stop,start1,stop1;
html=html.ToLower();
DateTime dt=DateTime.Now;
start=html.IndexOf("℃",0);
AllWeather="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<NewDataSet>\n";
AllWeather+="<Author>翔工作室技术副站长 傅昌铕--Monster</Author>\n<Table>\n<Title>今日天气</Title>\n<Highest>";
stop=html.IndexOf("<",start);
AllWeather+=html.Substring(start,stop-1).ToString()+"</Highest>\n<Lowest>";
start=html.IndexOf("℃",stop);
stop=html.IndexOf("<",start);
AllWeather+=html.Substring(start,stop-1).ToString()+"</Lowest>\n";
start1=html.IndexOf("class=\"pub12blue\" width=\"107\">",stop);
stop1=html.IndexOf("</td>",start1);
AllWeather+="<Wind>"+html.Substring(start1,stop1-1).ToString()+"</Wind>\n</Table>\n<Table>\n<Title>明日天气</Title>\n<Highest>";
start=html.IndexOf("℃",stop);
stop=html.IndexOf("<",start);
AllWeather+=html.Substring(start,stop-1).ToString()+"</Highest>\n<Lowest>";
start=html.IndexOf("℃",stop);
stop=html.IndexOf("<",start);
AllWeather+=html.Substring(start,stop-1).ToString()+"</Lowest>\n";
start1=html.IndexOf("<span class=\"pub12blue\">",stop1);
stop1=html.IndexOf("<",start1);
AllWeather+="<Wind>"+html.Substring(start1,stop1-1).ToString()+"</Wind>\n</Table>\n";
AllWeather+="</NewDataSet>";
StreamWriter writer=new StreamWriter(fs,Encoding.UTF8);
writer.WriteLine(AllWeather);
writer.Close();
fs.Close();
sr.Close();
s.Close();
wresp.Close();
//}
//catch
//{
//}
}
}
}

解决方案 »

  1.   

    晕了..以后会更难混了..ASP.net一出来就是一大堆的代码.asp的少了很多
      

  2.   

    我把代码缩小一些,我多次检查断点,发现问题可能就出现在下面的代码里面
    Uri myUri=new Uri("http://cn.weather.yahoo.com/CHXX/CHXX0437/index_c.html");
    WebRequest wrq=WebRequest.CreateDefault(myUri);
    //wReq.Credentials = new NetworkCredential("account","password","domain");
    Stream s=wrq.GetResponse().GetResponseStream();
    StreamReader sr=new StreamReader(s,Encoding.Default);
    FileStream fs=new FileStream(Request.PhysicalApplicationPath+"\\weather.xml",FileMode.Create,FileAccess.ReadWrite);

    StreamWriter writer=new StreamWriter(fs,Encoding.UTF8);
    writer.WriteLine(sr.ReadToEnd());
    而这短代码如果不用线程调用的话就不会出现问题,如果创建线程调用就有问题了
      

  3.   

    我估计很有可能是读取的网页与创建的线程安全上的问题,
    我看到SerializationException上面说有时候也会给线程带来安全问题,
    但是解决方法还不知道
      

  4.   

    yun
    dou mei you ren hui da !