0

I have a C# WPF application that is experiencing a weird issue. The app uses the MS Enterprise Library (Logging) which is configured using the app.config. My deployed files hence are:

(names changed, filename lengths correct)

XXXXXXXXXXX.EXE

XXXXXXXXXXX.EXE.CONFIG

Normally this works just fine. However, in one bizarre situation the app is launched by another program that calls the EXE based on it's shortname (XXXXXX~X.EXE). The EXE starts but then proceeds to look for an app.config that doesn't exist (XXXXXX~X.EXE.CONFIG ) and the Logging class fails to initialize.

I can't change the program that launches us so I'm trying to figure out ways guarding against this in my WPF code. Thoughts are...

1) Rename my EXE and create a man in the middle EXE.

2) Detect how my EXE was launched and relaunch it correctly.

3) Some kind of AppDomain / ConfigurationManager repointing ( Is this possible? )

4) Use the installer to clone the App.Config to the short file name version (confirmed works)

Has anyone ever seen this before and have any suggestions / insight?

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • Not much you can do to fix a crappy app. Creating a copy of the .config file with the short name is not terribly reliable. The simple solution is to use a filename with 8 characters or less. – Hans Passant Nov 02 '12 at 15:15
  • I understand about fixing the other crappy app but the app I'm working on was a refactoring of another crappy app and it needs to fit into the original infrastructure of all the things around it for the moment. – Christopher Painter Nov 02 '12 at 16:44

2 Answers2

1
string realAppName = Process.GetCurrentProcess().MainModule.FileName;
System.AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", realAppName + ".config");
YurikoEX
  • 105
  • 2
  • 9
0

If you can change the exe to start then call

start.exe XXXXXXXXXX.exe
Yann Olaf
  • 597
  • 3
  • 12