There’s a function that I have written which basically does encryption for me 4 times in a day and writes the encryption in a xml file. Now we have 4 regions them being Dev,QA,ITE and PROD. I did not get any errors in DEV,QA,ITE but in PROD weird things are happening.
The first exception on which the code failed was this
Invalid XML document, The document does not have a root element.. at System.Xml.XmlDocument.Save(String filename)
and got this exception too:
The process cannot access the file 'configfile.xml' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, StringmaybeFullPath)at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Xml.XmlDocument.Save(String filename)
I have a feeling this is happening due to concurrent requests. The programming language used is C# with ASP.NET 2.0.
Can someone enlighten me?
The “file being used by another process” exception is certainly down to trying concurrent access (and this could be from the current process).
Process Explorer can help here: search for the name of the file to see what processes have handles to the file.
With respect to the XML error: either XML is “Well Formed” or it isn’t XML. And that means having exactly a single root element.
Well formed:
Not XML:
There is limited capability within .NET for loading “XML Fragments” which can break the document rules, but this is really for insertion into a complete document, not as an alternative to the XML rules.