Just when I thought we were out of the dark ages… something hit me right out of the blue.
During the summer something strange has happened, which I suspect happened because of some Microsoft security update. That is at least more probable than an ill-willing gnome in my machine fiddling with some bits. But you never know.
What has happened is that the
System.Windows.Forms.Application.ExecutablePath
property all of a sudden returns an incorrect result if the path contains a “non-ASCII” character like our swedish charaters åäö!!!
Replacing it with a
System.Reflection.Assembly.GetExecutingAssembly().Location
fixes the problem.
Demonstration:
- Fire up a new windows forms project and add “MessageBox.Show( Application.ExecutablePath );” to the default form’s constructor.
- Compile and place the exe in a folder called “c:\Our Application”.
- Run and you get “C:\Our Application\WindowsApplication1.exe”.
- Now rename the folder to “c:\Vår Applikation”.
- Run and you get “C:\V�r Applikation\WindowsApplication1.exe”. Where the “�” character is #65533.
The scary thing is that this behavior just changed over night.
