I encountered some odd behaviour from the XmlReader today on a BizTalk project. I’ve got a nice little helper method that rips through an xml document and aggregates all schema validation errors. We use this for a number of projects where we validate messages against a trading partners schema after transformation and before transport. If we get errors we shoot them off via an SMTP port to be addressed by a sys admin.
Previously I had been using the XmlValidatingReader but seeing as that’s been depricated in .NET 2.0 I upgraded to using XmlReader and XmlSettings. I performed a few unit tests and it worked perfectly. We promoted the solution to our test environment where we loaded it up with approx. 300 identical messages. Under these circumstances we noticed we could consistently generate erroneous validation errors in this scenario. In all cases where we got an error it would say a field was missing from the XML document that was actually there. Running the 300 messages through at a rate of 2-3 per second resulted in flawless operation.
Its a bit of a mystery. I switched my code back to the XmlValidatingReader for a sense check and sure enough it worked fine under load. A bit more research required on that one I think!