Overview
The above message can be quite frustrating if you don't know why you are getting it. Microsoft's take on this particular error message when you try to compile you BizTalk Server project is pretty much detailed in the article:
One of the times I have come across this problem is when I want to create a message in an orchestration that is not the result of a transform. At first I was confused by this error, but it does sort of make sense. To resolve the issue I figured that, if Visual Studio can create a document instance, then so can I.
The Problem
Consider the following scenario:
An orchestration wants to call a web service to save some data away to a third-party service. Should this web service raise an exception for any reason, I want to create an instance of a message that contains an error report and then send it off to another orchestration for processing. For this purpose I have create a schema for my error report message. I don't have ownership of the web service, so I will make my call to it in a Scope shape and to that scope shape, I will add an exception handler to contain my error reporting.
All I want to do is set four properties in my error message; sender email, recipient email, subject and body. If I just use a Message Assignment shape inside a Construct Message shape and try to set these properties, we get the error.
Solution
Using a couple of the less-than-well documented assemblies, we can create an empty XML instance of our document schema. To do this, I added a helper class to my solution that would contain a series of helpers that could create an instance of a specified document schema. These can be found in the following location on your BizTalk Server:
C:\Program Files\Microsoft BizTalk Server 2006\Microsoft.BizTalk.Pipeline.dll
C:\Program Files\Microsoft BizTalk Server 2006\Microsoft.XLANGs.BaseTypes.dll
Following that, I simply need to create a method for each message I need to create. So for my error message type, I created the following:
/// <summary>
/// Creates an empty instance of the Error Message schema.
/// </summary>
/// <remarks>
/// Error handling has been left out in the hope that BizTalk Server might be able to raise the error message.
/// </remarks>
/// <returns>XmlDocument instance of the EBiz ErrorMessage schema</returns>
public static XmlDocument ConstructEBizErrorMessage()
{
Type MessageSchemaType = typeof(TestProject.BizTalk.EBiz.ErrorMessage);
DocumentSpec DocumentSpecification = new DocumentSpec(
MessageSchemaType.FullName,
MessageSchemaType.Assembly.FullName
);
XmlDocument SchemaInstance = new XmlDocument();
using (StreamReader InstanceStreamReader = new StreamReader(DocumentSpecification.GetDocSchema().CreateXmlInstance()))
{
SchemaInstance.Load(InstanceStreamReader);
}
return SchemaInstance;
}
The class library with this method is then referenced by my BizTalk Server project that contains the orchestration and can be called from within a Message Assignment shape to effectively initialize the instance of the message so that the properties can be set.
The nice thing is, when I update my schema in the BizTalk Server project, this helper class needs no updating and will just work.
Lovely - time for a cup of tea. :)
Versions
Metadata