1

I have created an app in WPF which is just polling app. Now I want to start that app on windows Startup (after user login). I also created an installer package using Wix Toolset which adds a registry key to Software\Microsoft\Windows\CurrentVersion\Run. Program actually tries to run but gives no error. I was able to get error from Windows Event Viewer and I cannot understand where this error is generated.

Stack Trace:

Application: icBlync.exe
Framework Version: v4.0.30319
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.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(System.Uri, System.IO.Stream, System.Windows.Media.Imaging.BitmapCacheOption, System.Guid ByRef, Boolean ByRef, System.IO.Stream ByRef, System.IO.UnmanagedMemoryStream ByRef, Microsoft.Win32.SafeHandles.SafeFileHandle ByRef)
   at System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(System.Uri, System.Uri, System.IO.Stream, System.Windows.Media.Imaging.BitmapCreateOptions, System.Windows.Media.Imaging.BitmapCacheOption, System.Net.Cache.RequestCachePolicy, Boolean)
   at System.Windows.Media.Imaging.BitmapFrame.CreateFromUriOrStream(System.Uri, System.Uri, System.IO.Stream, System.Windows.Media.Imaging.BitmapCreateOptions, System.Windows.Media.Imaging.BitmapCacheOption, System.Net.Cache.RequestCachePolicy)
   at System.Windows.Media.Imaging.BitmapFrame.Create(System.Uri, System.Net.Cache.RequestCachePolicy)
   at System.Windows.Media.Imaging.BitmapFrame.Create(System.Uri)
   at icBlync.Windows.SettingWindow..ctor()
   at icBlync.App..ctor()
   at icBlync.App.Main()

Pls Help.

  • Well, to me it looks like the app (icBlync.exe) is started. When trying to access some file or directory (read/write) it breaks because the directory is not created yet. Do you have any code that does filesystem operations or respectively are you sure your installer creates all the required paths? – Markus Deibel Mar 29 '17 at 13:35
  • 2
    Do note that your working directory might not be the same so if you're using relative paths it may be a problem. – Sami Kuhmonen Mar 29 '17 at 13:42
  • App runs perfectly if i run it manually. This error occurs at automatic startup. – Hamza Ikram Mar 29 '17 at 13:48
  • 2
    [this answer](http://stackoverflow.com/a/2823044/15498) shows the bit you probably need. – Damien_The_Unbeliever Mar 29 '17 at 14:01
  • Thanks @Damien_The_Unbeliever for helping me. – Hamza Ikram Mar 30 '17 at 13:24

1 Answers1

2

When App starts from Startup, working directory was not the installed directory. So when the app tries to load Icons, it gives System.IO.DirectoryNotFoundException.

I just changed the working directory to the Installed directory using:

Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);