When Naming a Configuration File program.exe.config is Bad

Posted by Kirby Turner on April 25, 2007

I learned a valuable lesson today about naming configuration files for my programs. When I started building.NET applications I followed the .NET convention for naming program configuration files: MyProgram.exe.config

These days I write less .NET applications and more native Windows applications using Delphi. I continue using the .NET naming convention for configuration files for all my programs even native Windows applications. This hasn’t been a problem until today.

Today I embedded a manifest into a program and when I ran the program I got the following error message:

<div class="quote">
C:\MyProgram.exe

This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
</div>

Without the manifest the program ran fine, but the program failed each time the manifest was included. I first thought a problem was with the manifest. I review the manifest over, and over, and over again. I even used a manifest from another application that does not have the problem. After banging my head on the wall for a couple of hours I found the source of the problem, and it wasn’t the manifest at all.

Like all my programs, this particular program creates a configuration file using the .NET naming convention MyProgram.exe.config. But in this one case the configuration file is stored in the same directory as the program file, and here in lies the problem.

Apparently Windows XP, and I assume Vista as well, expects the program configuration file to be based on some specific config file schema when the manifest is embedded in the program file even if the program is a native Windows program. I knew this to be true with .NET applications but I didn’t realize the same is true for native Windows applications.

I have not spent time figuring out the expected schema. I suspect it is the .NET config file schema, but I now follow a new naming convention. I do not name my config files MyProgram.exe.config any more. Instead I use MyProgram.config, which does not have any negative side effects when stored in the same directory as the program file.

Update: If you want to use the .NET config file naming convention for your native Windows application, your .config file must be an XML, and the root element must be . Other root elements might be allowed but I know works.


Posted in programming. Tagged in windows.


Related Articles