2017-03-29 123 views
0

我在WPF中创建了一个应用程序,它只是轮询应用程序。现在我想在Windows启动时启动该应用程序(用户登录后)。我还使用Wix Toolset创建了一个安装程序包,它将一个注册表键添加到Software \ Microsoft \ Windows \ CurrentVersion \ Run。程序实际上试图运行,但没有发生错误。我可以从Windows获得错误事件查看器,我无法理解此错误产生的位置。Wpf应用程序不在启动时启动,而是手动运行?

堆栈跟踪:

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() 

请帮助。

+0

好了,对我来说,它看起来像应用程序(icBlync.exe)开始。当试图访问某个文件或目录(读/写)时,它会因为目录尚未创建而中断。你有没有执行文件系统操作的代码,或者你是否确定你的安装程序创建了所有必需的路径? –

+2

请注意,您的工作目录可能不一样,所以如果您使用相对路径,它可能是一个问题。 –

+0

应用程序运行完美,如果我手动运行它。自动启动时发生此错误。 –

回答

0

当应用程序从启动启动时,工作目录不是安装的目录。所以当应用程序尝试加载图标时,它会给出System.IO.DirectoryNotFoundException

我刚换了工作目录使用所安装的目录:

Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath); 
相关问题