1

I'm writing a program in Visual Studio 2015. When I build and install using setup wizard then find the installed application and double click on it I get no issues. The app opens and is fully functional.

Lately I've tried adding a "auto launch after setup" to my app using this: This solution. It builds successfully and installs but doesn't run. Instead I get this error in the event viewer:

Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.DirectoryNotFoundException
   at System.IO.__Error.WinIOError(Int32, System.String)
   at System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean, Boolean, Boolean)
   at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare)
   at System.Drawing.Icon..ctor(System.String, Int32, Int32)
   at System.Drawing.Icon..ctor(System.String)
   at myApp.Form1.buildIconArray(System.String)
   at myApp.Form1..ctor()
   at myApp.Program.Main()

Here is buildIconArray

public void buildIconArray(string name)
        {
            for (int i = 0; i <= 100; i++)
            {
                iconArray[i] = new Icon("icons/" + name + "/" + i + ".ico");
            }
        }

iconArray is defined way above:

Icon[] iconArray = new Icon[101];

Like I said, even doing the installation with this modification script I am able to open and operate the program normally and without error.

It kind of seems like the problem might be with systemio? When I remove this function the application does no error but it also does not build any icons.. :/

I am not using OneClick installer, couldn't figure out how to get it to work in VS2015. I'd be willing to try it if someone can point me in the right direction. I"m using this: Microsoft Visual Studio 2015 Installer Projects

Community
  • 1
  • 1
Rymn
  • 186
  • 1
  • 8
  • you are doing OneClick publishing right? Also where are the icons stored and what are doing with them? – Jacobr365 Feb 23 '16 at 19:32
  • Nope, couldn't find it out. Using: [Microsoft Visual Studio 2015 Installer Projects](https://visualstudiogallery.msdn.microsoft.com/f1cc3f3e-c300-40a7-8797-c509fb8933b9) – Rymn Feb 23 '16 at 19:35
  • 1
    At a guess - I would say that your **working directory** when launching after the installer completes is **not** the same working directory as when you launch the app by double clicking on it. So the icon path is relative to the current working directory, and looks like it doesn't exist. If the `icons` folder is under the installation directory of the app, then change the paths that you build to include the full path to the application. – Brendan Green Feb 23 '16 at 20:40
  • Thanks Brendan, that was it. Just started using absolute paths using Application.StartupPath – Rymn Feb 23 '16 at 22:29

1 Answers1

1

Thanks to Brendan Green in the comments from the OP.

The problem was the application was the installation. The application ran from the installer directory and not the installation directory.

Rymn
  • 186
  • 1
  • 8