BizTalk: Type 'System.Xml.XmlDocument' in Assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

by matt 27. May 2008 10:44

I ran in to this problem recently while developing a solution for a client.  For me it took a little while to figure out what was happening and the error was reported to be coming from a send shape that sent a message of type System.Xml.XmlDocument.

While this is the correct place for the error to be raised, it was not strictly related to them message that I was trying to send.

The actual cause of the problem is that I have a class that is used to return information back from a series of helper methods in a library that I have built.  The class has 3 public properties:

  • Result: An inumeration indicatign the level of success
  • Document: when successful, this is an XML document otherwise, it is null.
  • Exception: this is null if the call was successful, otherwise it contains all relevant information to describe the failure.

Document is a System.Xml.XmlDocument and it is this that is causing the error.  Essentially, BizTalk Server seems to be trying to serialize this class, either for dehydration, analyst reporting or some other reason.  All we need to do to avoid this error is simply mark the property as nonserializable, I.e:

/// <summary>
/// Contains the result of a receipt processing attempt.
/// </summary>
[Serializable()]
public class ReceiptResult
{
    private ReceiptSuccessResult _result;
    [NonSerialized()]
    private XmlDocument _document;
    private ReceiptException _exception;

    /// <summary>
    /// Gets the overall result of the validation attempt.
    /// </summary>
    public ReceiptSuccessResult Result
    {
        get { return this._result; }
    }

    /// <summary>
    /// Gets any XML document that may have been returned from the validation attempt.
    /// </summary>
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1059:MembersShouldNotExposeCertainConcreteTypes", MessageId = "System.Xml.XmlNode")]
    public XmlDocument Document
    {
        get { return this._document; }
    }

    /// <summary>
    /// Gets any exception that was returned from the validation attempt.
    /// </summary>
    public ReceiptException Exception
    {
        get { return this._exception; }
    }

    public ReceiptResult(ReceiptSuccessResult result)
    {
        this._result = result;
    }

    public ReceiptResult(ReceiptSuccessResult result, XmlDocument document)
    {
        this._result = result;
        this._document = document;
    }

    public ReceiptResult(ReceiptSuccessResult result, ReceiptException exception)
    {
        this._result = result;
        this._exception = exception;
    }
}

After that (for me at least) the error goes away.

Tags:

.Net Framework | BizTalk Server

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar