I created the routine below based on a StackOverflow that gave me the idea. In BizTalk Orchestrations, we often email out error to a distribution list, and it’s a lot easier on the eye when the request and response XML messages are nicely formatted. “Pretty Print” is a term used by several utilities like XML Spy and the XML Tools PlugIn for NotePad++.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO; 

namespace MySite.Common.BizTalkUtil
{
    public static class XmlFormatter
    {
        // Neal Walters - added 09/11/2015 from 
        // http://stackoverflow.com/questions/203528/what-is-the-simplest-way-to-get-indented-xml-with-line-breaks-from-xmldocument
        public static string PrettyPrint(this XmlDocument doc)
        {
            var stringWriter = new StringWriter(new StringBuilder());
            var xmlTextWriter = new XmlTextWriter(stringWriter) { Formatting = Formatting.Indented };
            doc.Save(xmlTextWriter);
            return stringWriter.ToString();
        }
    }
}

Example Use:

//tempStrBuilder is an object of type StringBuilder 
tempStrBuilder.Append("There was a SOAP 1.1 Fault. Check service for errors." + System.Environment.NewLine);
tempStrBuilder.Append("===========================" + System.Environment.NewLine);
tempStrBuilder.Append("Inbound Request:" + System.Environment.NewLine);
tempStrBuilder.AppendLine(MySite.Common.BizTalkUtil.XmlFormatter.PrettyPrint(xmlDocReq));
tempStrBuilder.Append("===========================" + System.Environment.NewLine);
tempStrBuilder.Append("SOAP Fault:" + System.Environment.NewLine);
tempStrBuilder.Append(MySite.Common.BizTalkUtil.XmlFormatter.PrettyPrint(vSOAPErrorXML));
// Then the error can be include in the body of an email 

Pretty Print XML in NotePad++

If you just need to format XML on your PC, consider adding the XML PlugIn for NotePad++ (a great free editor).

NotePad++ Pretty Print for XML

NotePad++ Pretty Print for XML

CNLT-ALT-SHIFT-B is the short cut, if you have enough fingers!

To install the Plugin, open the Plugin Manager as shown below.  Scroll down to the XML Plugin, and simply install it, then it restarts NotePad++ and it should be there.  Only takes two minutes or less.

Pretty Print XML in XSLT or BizTalk Mapper

From the map grid, right-click properties. In the properties window, not the “Indent” property, which says “Specified additional white space to add whne outputing the result tree; the value must be “yes” or “no”.

Plugin Manager

Plugin Manager

Presumably, that would set the XSLT code as follows, but I haven’t proven that yet.

 <xsl:output method="xml" indent="yes"/>

Reference: XSLT Syntax for Indenting, i.e. Pretty Print

Yes, sadly I’m still using Windows 2003 task scheduler. I needed to set up a job for the last day of the month. Some brilliant blog shows how to do it the DOS Command Prompt, something like this:

schtasks /create /tn MonthlyExtractLD /sc MONTHLY /M * /mo LASTDAY /ru "xxx\yyyy" /rp zzzzz /tr "C:\program files\if
s applications\data transformation services\DTS Executor.exe /JOB E:\MyDir\MyApp\Monthly_Extracts.XML"
SUCCESS: The scheduled task "MonthlyExtractLD" has successfully been created.

Note: I had to do a “Run as” to get the command prompt to even work and avoid an error stating that I had to specify a system name. I was using domain account, not local account.

Then when I went to the GUI version, it simply showed 31 as the day of the month. So, just guessing here, I could have saved all that tedious typing and trial and error of the DOS Command Line and just entered 31 in the GUI to start with… DUH!

Last Day of Month - Using WIndows 2003 Task Scheduler

Last Day of Month – Using WIndows 2003 Task Scheduler

Error: Root Element is Missing

InstanceId: d1c2f87c-825b-4c6e-b01c-c93e50d63502
Shape name: msgABCDetail
ShapeId: 33d0d3ac-ae45-408c-8224-f42725877a2b
Exception thrown from: segment 4, progress 22
Inner exception: Root element is missing.

Explanation(s)

This error occurs in an orchestration, typically after you have run a map, and the map doesn’t create any output.

The map is in a construct statement, and presumably the message created in the construct statement should not be empty.

The way to test or fix this is as follows:

1) Obtain a copy of a the message that goes into the map (might have to add debug or write message to disk or trace), and save to disk.

2) Test that message in Visual Studio using the right click “Test Map” option on the map (first set the “TestMap Input Instance” property to the filename you saved from the step above.

3) Typically the issue is a namespace or higher level node is missing. This causes none of the xpaths in the XSLT to match, and thus nothing is generating on the “right side” of the map. When you test the map, the Output window will show something like this: “The output is stored in the following file: xxx.xml”. If you cntl-click on that file, that file will open. In all likelihood it will be empty (blank). [If it has data in it, there is a chance the code you are running doesn’t match the current version of the source code/map you are testing, indicating you might need to redeploy.]

4) To check further, you can also check the file against the schema, to make sure it is valid. This may help indicate an element name or namespace that is wrong that could cause the map to result in empty output. Set the schema property “Input Instance Filename”, then right click on the schema and select “Validate Instance”. If it fails, you might try generating an instance, then use a file compare or your own eyeballs to compare the generated instance to the instance you were validating (experience teaches you what to look for).

Here’s a specific case I dealt with today. My data file had a root element named eisresultset. It was built by xpathing to a node of the data data returned to us by a vendor. Due to the way the vendor packs the data in a generic XmlDoc packet, the WSDL did not build the schemas for us, and I had to do it manually. When I built the schema for esiresultset, I misspelled the root element name and had esiresultset. The reversal of those two letters make a huge difference!

When I validated the data instance against the schema, the output window told me clearly:
e:\MyDir\MySubDir\map_EsiResultSet_To_DBTableMotoDetails_TestIn1.xml: error BEC2004: The ‘eisresultset’ element is not declared.

The second mistake I made, was in my map, I had mapped eisrecord, a separate schema with that repeats inside of eisresultset. So mapping a schema that starts with a higher level element than what I mapped would never result in a good map output.

This is a “back to the basics” post with a list of reasons BizTalk might not be processing (consuming) your file that you have placed (dropped) in a directory associated with a Receive Location.

1. Are the Host Instances started? (Specifically the Host Instance associated with the Receive Location).  Be sure and refresh (F5 or right-click refresh) to make sure you are not looking at old statuses.

Each receive location has a “Receive Handler”. See Figure 1 below.

See Figure 2 below to check if the Host Instances are started. Be sure and refresh (F5 or right-click refresh) to make sure you are not looking at old statuses.

Figure 1 - Receive Location - Receive Handler (Host Instance)

Figure 1 – Receive Location – Receive Handler (Host Instance)

In the case above, the Receive Location Hander is BizTalkServeApplication. So it doesn’t matter that the Rosetta Host Instance is not started.

Figure 2 - Status of Host Instances

Figure 2 – Status of Host Instances

2. Make sure the Receive Location itself is “Enabled”. The figure below doesn’t show, but I opened BizTalk Admin console, navigated to the Application on the left menu, then expanded the “Receive Locations”

Figure 3 - Receive Location Status

Figure 3 – Receive Location Status

3. Check Windows Application Event Viewer for Errors:

For example, here is an error I had today:
The FILE receive adapter cannot process file e:\Messages\Charter\Inbox\StarterParams\StartParams_Prod.xml because of one of the following reasons:
1) The file is read-only.
2) The file is a system file.
3) The FILE receive adapter does not have write permissions on the file.

To see if the file is read only, right click on the file and make sure the checkbox next to “read-only” attribute is NOT checked. Also make sure the file you are copying/dropping into the pickup directory is not “read-only”, because that attribute sticks when you copy it. NOTE: You might have a sample file in your Visual Studio Project, then when you check that project in to TFS (or some other source control system), the read-only attribute of that file is turned on. You might want to have a copy of your file for testing that is not part of TFS check-in so that the read-only attribute will stay off.

To check security, from Windows Explorer, right click the directory (not the file), click on the Security tab, and make sure that the userid that runs the Receive Handler Host Instance (see Figures 1 and 2 above) have Full Control. If in doubt, you could always add the user “Everyone” and give it full access. Then once you get it working, go back and tighten-up the security. If you are working on your own laptop or development computer, the security probably doesn’t matter. But on a shared development, QA, or production environment, security can be very important.

4. Consider checking the CPU performance on the machine.

I’ve seen cases where there is a task using 100% of the CPU, and that is preventing the BizTalk host instance to do its work.

The short cut to open Windows Task Manager is Cntl-Shift-Escape.  I like to check the “Performance tab” to see what CPU Usage is, if it is high, and how long it has been high. If it is really high, like 90-100%, you can click Processes (then sort by CPU) and find out which task is taking all the CPU.

Figure 4 - Windows Task Manager

Figure 4 – Windows Task Manager

 

I was getting this error first “namespace attribute of an import must not match the real value”.

I had a group schema, that had a repeating record of a second schema. That second schema did not have any Target Namespace, to match what a trading partner had given us.

This StackOverflow article reminded me that there are times to use INCLUDE instead of IMPORT.  So in the group schema, I clicked on <Schema> in the upper left of the Schema Editor/Viewer.  Then I used the “Imports” in the property window to delete the Imports of my second schema, and change it to an Includes.  I actually had trouble deleting it, and had to edit the schema.xsd in Notepad.  Then I had to re-add the record and reassociated the DataStructure property.

When I did the above, I started getting this error:
BEC2017: Node “” – This schema file has a TypeName that collides with the RootNode TypeName of one of its root nodes. Make sure that they are different.

This old blog by Stephen Thomas (on GeeksWithBlogs) helped. I realized I needed to click on the .xsd in the Solution Explorer, and just change the schema File Type.  I simply added the word “Type” on the end of what was already there.