Bug in OpenExeConfiguration(exePath)

  • Thread starter Thread starter leotohill
  • Start date Start date
L

leotohill

Problem: The Configuration object created by this method looks for a
file with an extra ".config" suffix, as in
"configtest.exe.config.config"


Try this test:
create a config file with a simple key/value setting in it, and store
the file in c:\temp\configtest.exe.config.

then run

Configuration config =
OpenExeConfiguration("c:\\temp\configtest.exe.config");
Console.WriteLine(config.FilePath);

You'll see that the filename is "c:\temp\configtest.exe.config.config".
Note the extra "config" extension! That file of course does not
exist, so the settings all come up empty.

OpenExeConfiguration checks for the existence of the file you specify,
so you can't work around this by coding
"OpenExeConfig("c:\temp\configtest.exe")

However, there is a clumsy workaround. Create 2 configuration files,
one named "configtest.exe.config" and the second named
"configtest.exe.config.config". The first one allows the OpenExeConfig
to succeed, and the second one is actually used for reading the values.


Leo Tohill
 
Holy crap! Thanks, I've spent like 2 hours now trying to figure out why it
didn't seem to be getting the right config file.

THANKS!
 
My understanding of the problem was a little off. Here's a better
description of the problem and the workaround:

OpenExeConfiguration(exeFile) checks for the existence of the filename
provided, and then uses a file with ".config" added to that name. So
if you want to use a file named "configtest.exe.config", you need to
specify the file named "configtest.exe", and that file must exist in
the same folder as the config file.

The specified file doesn't have to be a valid exe or assembly: it
could, for example, contain text. Which is a good thing, because if
you wanted to use a file named "web.config" you'd need to specify a
file named "web".

See
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=208159
 
Back
Top