claracruz
asked on
XML and ASP.NET
Hello experts,
I have a class that starts as follows;-
namespace ShoppingCartEngine
{
/// <summary>
/// Summary description for CartEngine
/// </summary>
[Serializable]<----------- ---------- ---------- ---------- --------PL EASE NOTE THIS LINE
public class CartEngine
{
}
}
Now when I try to load my XML File like so;-
//Load CartXML
oXmlDoc = new XmlDocument();
try
{
oXmlDoc.Load(HttpContext.C urrent.Ser ver.MapPat h("XMLFile .xml"));
}
catch (Exception ex)
{
HttpContext.Current.Respon se.Write(" <br>Error: <br>" + ex.Message);
}
I get the following error;-
Type 'System.Xml.XmlDocument' in Assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193 4e089' is not marked as serializable.
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.Runtime.Serializati on.Seriali zationExce ption: Type 'System.Xml.XmlDocument' in Assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193 4e089' is not marked as serializable.
What does this error mean?
How do I fix it.
Thank you
I have a class that starts as follows;-
namespace ShoppingCartEngine
{
/// <summary>
/// Summary description for CartEngine
/// </summary>
[Serializable]<-----------
public class CartEngine
{
}
}
Now when I try to load my XML File like so;-
//Load CartXML
oXmlDoc = new XmlDocument();
try
{
oXmlDoc.Load(HttpContext.C
}
catch (Exception ex)
{
HttpContext.Current.Respon
}
I get the following error;-
Type 'System.Xml.XmlDocument' in Assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193
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.Runtime.Serializati
What does this error mean?
How do I fix it.
Thank you
ASKER
I found a solution, but i don't know how to implement it. Apparently, I need to implement an interface with strings instead or something about implement Iserializable, how is this done.
ASKER
AAH!!!, I got it..
I was declaring XmlDocument oXmlDoc; as a private member of the class, when I changed this to the following;-
public static XmlDocument GetColums()
{
//load cart colums from cart.xml
XmlDocument oXmlDoc;
oXmlDoc = new XmlDocument();
try
{
oXmlDoc.Load(HttpContext.C urrent.Ser ver.MapPat h("XMLFile .xml"));
}
catch (Exception ex)
{
HttpContext.Current.Respon se.Write(" <br>Error: <br>" + ex.Message);
}
return oXmlDoc;
}
Thus declaring my oXmlDoc within that method, and it worked fine. So then I do the follwoing where i need the doc;-
XmlDocument oXmlDoc;
oXmlDoc = new XmlDocument();
oXmlDoc = GetColums();
I was declaring XmlDocument oXmlDoc; as a private member of the class, when I changed this to the following;-
public static XmlDocument GetColums()
{
//load cart colums from cart.xml
XmlDocument oXmlDoc;
oXmlDoc = new XmlDocument();
try
{
oXmlDoc.Load(HttpContext.C
}
catch (Exception ex)
{
HttpContext.Current.Respon
}
return oXmlDoc;
}
Thus declaring my oXmlDoc within that method, and it worked fine. So then I do the follwoing where i need the doc;-
XmlDocument oXmlDoc;
oXmlDoc = new XmlDocument();
oXmlDoc = GetColums();
It would have helped if you had included the full code as there was no way I could have caught that for you since you left that portion out of the posted code...
Anyway you can ask to have your points refunded ad this question closed by posting in community support.
Anyway you can ask to have your points refunded ad this question closed by posting in community support.
No objection - it can be closed now.
:o)
:o)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You may want to try a simpler example - i.e. outside of your class - to see if something went wrong.
Also you can try not catching the error and see if you get the same message, or more details...