C# Console App Deleting my config file - HELP!

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

I have a simple C# console app that needs to read the appname.exe.config
file to get db connect strings etc. from the <appSettings>. When the app
starts, it deletes the file! I can't figure it out. When I set a break point
on the first line in MAIN and check for the file, it is gone!

This is a 4 hour app, but I have spent all day trying to understand why the
config file is being deleted. Any help would be greatly appreciated.

Thanks very much in advance,

Richard Kessler
 
Hello Richard,

Thanks for your post. As I understand, the proboem you are facing is that
your application configuration file will be deleted automatically. To
narrow down the problem, I think more information is needed:

1. Where does the config file reside? Did you add it to your project?

2. Does the problem occur to a specific project or to all the projects? I
recommend you perform the following steps to check it:
a. Create a new C# console application.
b. Select the menu "Project" -> "Add New Item...".
c. Double-click the "Application configuration file" to add a config file.
d. Run the application and see if it will be deleted.

3. It seems to me that file is gone before starting your console
application, I believe that it may be deleted by other process say, VS .NET
IDE. Please use FileMon to find out which process deletes the config file.
You can download FileMon utility at
http://www.sysinternals.com/ntw2k/source/filemon.shtml.

I look forward to your response.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
I have a simple C# console app that needs to read the appname.exe.config
file to get db connect strings etc. from the <appSettings>. When the app
starts, it deletes the file! I can't figure it out. When I set a break point
on the first line in MAIN and check for the file, it is gone!

Yes, the IDE will wipe out the target directory when compiling.

The solution is to add your config file to your project, and make sure
to call it "app.config" (exactly that - DO NOT call it anything else,
DO NOT expand "app" to be your app's name, or anything like that!).

In this case, the VS.NET IDE will always but your app.config file,
renamed to <yourproject.exe.config>, into your output directory.

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Hi,

Where do you have the file "appname.exe.config"?? in the Bin folder??
I had the same problem with a config file in the bin folder. when th
eproject is compiled it deletes all the bin folder content.
 
Back
Top