Link to home
Start Free TrialLog in
Avatar of claracruz
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]<-------------------------------------------------PLEASE 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.Current.Server.MapPath("XMLFile.xml"));
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.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=b77a5c561934e089' 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.Serialization.SerializationException: Type 'System.Xml.XmlDocument' in Assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.


What does this error mean?
How do I fix it.

Thank you

Avatar of mrichmon
mrichmon

It doesn't sound like the error is complaining about your code, but about the XmlDocument in the SYstem class.    Which is strange.   Since you are signing it with a public token - are you sure that this is correct?

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...
Avatar of claracruz

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.
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.Current.Server.MapPath("XMLFile.xml"));
            }
            catch (Exception ex)
            {
            HttpContext.Current.Response.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();
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.
No objection - it can be closed now.

:o)
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial