Root Element Is Missing: Validate Your Input
Confusing exception messages is the bane of all developer’s existence. In many cases, the error you see has nothing to do with the actual problem.
Today, a message similar to the following was haunting me:
There was a failure executing the send pipeline: “Microsoft.Practices.ESB.Itinerary.Pipelines.ItinerarySend, Microsoft.Practices.ESB.Itinerary.Pipelines, Version=188.8.131.52, Culture=neutral, PublicKeyToken=31bf3856ad364e35” Source: “XML assembler” Send Port: URI: Reason: Root element is missing.
Normally when this exception pops up, the first thing I do is validate the namespace and rootnode names against the expected schema to determine if they’re correct. Usually, this is where the fault will lie. Today, however, I was able to confirm that this was not the problem.
Fortunately, a simple map validation using my input showed me that one of my fields had data of the incorrect type.
Lesson: always do a map validation first.