Solving I/O Error 103 in LoadXMLDocument

In a Delphi console application that reads its configuration from an XML file, I unexpectedly ran into “I/O error 103”. I/O error 103 will look familiar to most of you Delphi developers, it means “File not open”. I traced it to this source line:

xmlcfg := LoadXMLDocument(FConfigFilePath);

LoadXMLDocument comes from the Delphi unit XMLDoc.pas, so the problem was not in my code. Ouch, this could mean trouble. But, the exact same unit was used in another (Forms) application where it worked perfectly fine. What was going on here?

The solution was fortunately deceivingly simple: the XMLDoc unit uses interfaces, so you need a CoInitialize() call before doing anything. As it turned out, my CoInitialize() call was too late. It was further down, right before initializing some ADO components, but after the attempt to read the configuration file. So the solution was to put


At the very top of my initialization code, before calling the configuration reader. Now it worked fine, no more “File not open” messages.

This proved once more that sometimes, the error message you get has little to do with the real issue at hand.

For reference: CoInitialize resides in the ActiveX unit.


Over Shiftkey
I am Maarten, owner of and chief software developer for Shiftkey software development from The Netherlands. I will be writing mainly about things I run into when programming in C# or Delphi.

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen. logo

Je reageert onder je account. Log uit /  Bijwerken )

Google photo

Je reageert onder je Google account. Log uit /  Bijwerken )


Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )

Verbinden met %s

%d bloggers liken dit: