Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7085841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:28:29+00:00 2026-05-28T07:28:29+00:00

I’m running a desktop application and when I reach this line: serializer.Serialize(new StringWriter(sb), value);

  • 0

I’m running a desktop application and when I reach this line:

serializer.Serialize(new StringWriter(sb), value);

It’s throws the following error:

There was an error generating the XML document.

This is the code:

public static string Serialize(object value)
    {
        var serializer = new XmlSerializer(value.GetType());
        var sb = new StringBuilder();
        serializer.Serialize(new StringWriter(sb), value);
        return sb.ToString();
    }

When I debug I see this in the Watch section:

    value.GetType().IsSerializable  true    bool

I’m setting this before declaring values‘s class:

[Serializable]

Thank you in advance.

Exception detail

            System.InvalidOperationException was unhandled by user code
              Message="There was an error generating the XML document."
              Source="System.Xml"
              StackTrace:
                   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
                   at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
                   at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
                   at Pacer.PIA.UI.WindowsForms.Controls.Utility.Serialize(Object value) in E:\Projects\Indexing\Main\Source\Pacer.PIA\Source\Pacer.PIA.UI.WindowsForms\Controls\Utility.cs:line 55
                   at Pacer.PIA.UI.WindowsForms.Controller.MainForm.ActionLoad..ctor(Int32[] index, Object objValue) in E:\Projects\Indexing\Main\Source\Pacer.PIA\Source\Pacer.PIA.UI.WindowsForms\Controller\MainForm\ActionAdd.cs:line 37
                   at Pacer.PIA.UI.WindowsForms.MainForm.SearchLoadByLoadNumber(String loadNumber) in E:\Projects\Indexing\Main\Source\Pacer.PIA\Source\Pacer.PIA.UI.WindowsForms\Forms\MainForm.cs:line 3530
                   at Pacer.PIA.UI.WindowsForms.MainForm.rmedtLoadNumber_KeyPress(Object sender, KeyPressEventArgs e) in E:\Projects\Indexing\Main\Source\Pacer.PIA\Source\Pacer.PIA.UI.WindowsForms\Forms\MainForm.cs:line 1244
                   at Telerik.WinControls.RadItem.OnKeyPress(KeyPressEventArgs e)
                   at Telerik.WinControls.UI.RadTextBoxElement.textBoxItem_KeyPress(Object sender, KeyPressEventArgs e)
                   at Telerik.WinControls.RadItem.OnKeyPress(KeyPressEventArgs e)
                   at Telerik.WinControls.UI.RadTextBoxItem.TextBoxControl_KeyPress(Object sender, KeyPressEventArgs e)
                   at System.Windows.Forms.Control.OnKeyPress(KeyPressEventArgs e)
                   at Telerik.WinControls.UI.RadMaskTextBox.OnKeyPress(KeyPressEventArgs e)
                   at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
                   at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
                   at System.Windows.Forms.Control.WmKeyChar(Message& m)
                   at System.Windows.Forms.Control.WndProc(Message& m)
                   at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
                   at System.Windows.Forms.TextBox.WndProc(Message& m)
                   at Telerik.WinControls.UI.HostedTextBoxBase.WndProc(Message& message)
                   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
                   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
                   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
              InnerException: System.InvalidOperationException
                   Message="The type System.Drawing.Bitmap was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."
                   Source="niumy1xe"
                   StackTrace:
                        at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write4_Image(String n, String ns, Image o, Boolean isNullable, Boolean needType)
                        at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write5_BEDocument(String n, String ns, BEDocument o, Boolean isNullable, Boolean needType)
                        at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write6_BERequirement(String n, String ns, BERequirement o, Boolean isNullable, Boolean needType)
                        at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write8_BEMove(String n, String ns, BEMove o, Boolean isNullable, Boolean needType)
                        at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write9_BELoad(String n, String ns, BELoad o, Boolean isNullable, Boolean needType)
                        at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterBELoadCollection.Write10_ArrayOfBELoad(Object o)
                   InnerException:

The class:

    [Serializable]
public class BELoadCollection : List<BELoad>, ICloneable
{
    public BELoad FindByLoadId(string loadId)
    {
        return this.Find(load => load.LoadId.Equals(loadId));
    }

    public bool ExistsByLoadId(string loadId)
    {
        return this.Exists(load => load.LoadId.Equals(loadId));
    }

    public bool HasLoadsWithDocumentRequirementLinked
    {

        get
        {
            return this.Exists(load => load.HasDocumentsRequirementLinked);
        }
    }

    public void PrepareRequirementsToIndex()
    {
        this.ForEach(load =>
        {
            load.PrepareRequirementsToIndex();
        });

    }

    public bool HasLoadsReadyToIndex
    {

        get
        {
            return this.Exists(load => load.HasDocumentsRequirementReadyToIndex);
        }

    }

    public BERequirementCollection GetRequirementsReadyToIndex()
    {
        BERequirementCollection beRequirementsReadyToIndex = new BERequirementCollection();

        this.ForEach(load => beRequirementsReadyToIndex.AddRange(load.GetRequirementsReadyToIndex()));

        return beRequirementsReadyToIndex;
    }

    #region ICloneable Members

    object ICloneable.Clone()
    {
        return this.Clone();
    }

    public BELoadCollection Clone()
    {
        BELoadCollection BELoadCollectionClone = new BELoadCollection();

        for (int i = 0; i <= this.Count - 1; i++)
            BELoadCollectionClone.Add(this[i]);

        return BELoadCollectionClone;
    }

    #endregion
}

And this is BELoad (just the fields)

 public class BELoad : BEMetaData, ICloneable
{
    //Fields
    private BEMoveCollection beMoveCollection;

    public string LoadId { get; set; }
    public string Description { get; set; }
    public string DocumentType { get; set; }
    public string Vendor { get; set; }
    public string VendorCityState { get; set; }
    public string State { get; set; }
    public string EquipmentPrefix { get; set; }
    public string EquipmentNumber { get; set; }
    public string Driver { get; set; }
    public string Shipper { get; set; }
    public string ShipperCityState { get; set; }
    public string BillTo { get; set; }
    public string BillToCityState { get; set; }
    public string Consignee { get; set; }
    public string ConsigneeCityState { get; set; }
    public string Stop { get; set; }
    public string StopCityState { get; set; }
    public string Container { get; set; }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:28:30+00:00Added an answer on May 28, 2026 at 7:28 am

    There’s a hint in the stacktrace:

    InnerException: System.InvalidOperationException                    
        Message="The type System.Drawing.Bitmap was not expected. 
        Use the XmlInclude or SoapInclude attribute to specify types 
        that are not known statically." 
    

    System.Drawing.Bitmapis not Xml Serializable, hence the exception. Perhaps another way would be to use XmlIgnoreAttribute to ignore this property, or implement IXmlSerializableand serialize the image as an ascii blob if you really need it saved?

    See the related question & answer Serializing a Bitmap in C# to XML

    contributed by Conrad Frix in comments

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.