Thursday, August 3, 2017

ArgumentException : illegal characters in path

Today my colleague faced an interesting issue, he had build and deployed a an application which has a process which invokes a stored procedure, collects response  and does further processing. While testing he encountered below error in event log 

illegal characters in path

Why it happened


In order to invoke the Stored procedure, schema was generated from it and Message to be sent was constructed with the help of XML document variable.

                                     xDoc = new System.Xml.XmlDocument();

And instance of the SP request schema was loaded in it

                                    xDoc.Load("Generated instance");

And this is the place the issue was - incorrect method usage, correct method to be used is LoadXml().

Question might come in mind, why no error while compiling - it is because Load() and LoadXml() are both valid method for loading XML.


Although the purpose of both method is same i.e. to load XML but it differs in the way they work.
Load() loads from a certain source i.e. either from a stream, TextReader, path/URL, or XmlReader, whereas LoadXml() loads directly from a string i.e. the XML contained within a string.

Thus when used Load method, at runtime XLang engine looks for path of the source but as there was no path it threw an exception - illegal characters in path.


What to do



As here XML was to be read from string, LoadXml() method is the correct one, after doing this correction issue was resolved.


using loadxml method


No comments:

Post a Comment