Server Error in '/WebAddress' Application.
----------------------------------------------------------------------------
----
<Addr xmlns=''> was not expected.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.InvalidO perationExcepti on: <Addr xmlns=''> was not
expected.
Source Error:
Line 93: //create a serializer...
Line 94: XmlSerializer serializer = new
XmlSerializer(t ypeof(Entry));
Line 95: newEntry = (Entry)serializ er.Deserialize( f);
Line 96: }
Line 97: finally
Source File: .......global.a sax.cs Line: 95
Stack Trace:
[InvalidOperatio nException: <Addr xmlns=''> was not expected.]
Microsoft.Xml.S erialization.Ge neratedAssembly .XmlSerializati onReader1.Read4 _
Entry()
[InvalidOperatio nException: There is an error in XML document (2, 2).]
System.Xml.Seri alization.XmlSe rializer.Deseri alize(XmlReader xmlReader,
String encodingStyle)
System.Xml.Seri alization.XmlSe rializer.Deseri alize(Stream stream)
WebAddress.Glob al.LoadEntry(St ring filename) in
c:\inetpub\wwwr oot\webaddress\ global.asax.cs: 95
WebAddress.Defa ult.Page_Load(O bject sender, EventArgs e) in
c:\inetpub\wwwr oot\webaddress\ default.aspx.cs :44
System.Web.UI.C ontrol.OnLoad(E ventArgs e)
System.Web.UI.C ontrol.LoadRecu rsive()
System.Web.UI.P age.ProcessRequ estMain()
"pei_world" <pe*******@hotm ail.com> wrote in message
news:eP******** ******@TK2MSFTN GP09.phx.gbl...
I have followed a example from a book exactly, but it seems not working at
all.
can anyone tell me what is going on?
========= Global.asax.cs ============
public static Entry LoadEntry(Strin g filename)
{
//construct the path
String filepath = XMLFilePath + "\\" + filename;
FileStream f = null;
Entry newEntry;
try
{
//open the file
f = new FileStream(file path,FileMode.O pen);
//create a serializer...
XmlSerializer serializer = new XmlSerializer(t ypeof(Entry));
newEntry = (Entry)serializ er.Deserialize( f);
}
finally
{
//close the file
f.Close();
}
//retrun the entry..
return newEntry;
}
====== default.aspx.cs =======
//loading entry from xml file
Entry entry = Global.LoadEntr y("address.xml" );
this.lblCatalog .Text = entry.Catalog;
this.lblName.Te xt = entry.Name;
this.lblAddress .Text = entry.Address;
===== address.xml ========
<?xml version="1.0" encoding="utf-8" ?>
<Addr xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<Catalog>nove l</Catalog>
<Name>Sina</Name>
<Web>http://www.sina.com.cn </Web>
</Addr>