Runtime can not find xml files

I have a windows application that runs great in Debug/release mode.  I compile the setup.exe file using Inno Script Tool and include the xml files in the code.  When I run the setup.exe file the exe file is created in the proper directory along with the xml files.  So I know the files make it this far.

When I run the exe it does not find the xml files.

Below are some code snippets of how I am reading the xml files

In general declarations
Public path As String

Open in new window

In form load
path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

Open in new window

In the button action

Open in new window

In ai_weights.vm1_read_file
      Dim f As String = path & "\ai_tuning_vm1.xml"
      If (IO.File.Exists(f)) Then

Open in new window

When I break at the If ... Then statement the path is correct when I point at f string and as I said it works in debug mode

Thanks for the help,
Ron Wensley
Who is Participating?
Jacques Bourgeois (James Burger)Connect With a Mentor PresidentCommented:
If this code is in a .exe, simply use Application.ExecutablePath to retrieve the directory in which the application is installed.

If it is in a .dll, then you should go for GetCallingAssembly or GetEntryAssembly (depending on how the method is called) instead of GetExecutingAssembly.
Bob LearnedCommented:
For Windows Forms, what does Application.StartupPath return?
Jacques Bourgeois (James Burger)PresidentCommented:
By default, Application.StartupPath returns the same thing as the Application.ExecutablePath.

But if you create a shortcut to start the application, you can define a different StartupPath. Just right click on an application shortcut, and you will see a "Start in" option. This can be used to specify a default directory for data files that is different than the application directory.

But since the application .config file is in the application directory if you use the default configuration mechanism, ExecutablePath is most appropriate in most situations. If you were using StartupPath with the .config file, you would end up with exceptions at the launch of the application if a user ended up fooling around with the shortcut that launch it.
Bob LearnedCommented:
I don't use Windows Forms very much any more, so I was curious if there was a case where the two would be different, like from a unit test project...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.