安装后找不到System.io.filenotfoundexception图像 [英] System.io.filenotfoundexception image not found after installation

查看:116
本文介绍了安装后找不到System.io.filenotfoundexception图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..

我使用c#创建了一个WPF应用程序,其中包含带图像的上下文菜单..

我正在使用安装后启动我的应用程序的自定义操作..

当应用程序第一次启动时它会给我异常 System.IO.FileNotFoundException

但是当它出现时通过双击桌面图标手动启动没有异常被引发并且工作正常并且显示所有图像..

这里使用图像的代码..

hello everyone..
I created a WPF app using c# in which I have context menu with images..
I am using custom action to launch my application after installation..
As App launches first time it gives me exception System.IO.FileNotFoundException
but when it is launched manually by double clicking desktop icon no exception is raised and works fine and all images are shown..
here's code of using image..

titleMenuItem.Image = System.Drawing.Image.FromFile("test.ico");



但是当我在visual studio中运行应用程序时,没有异常被引发..

如果重要我正在使用visual studio安装程序..



我尝试了什么:



我将图像放在应用程序的bin / debug文件夹中,并在设置的应用程序文件夹中。

推荐答案

问题可能归结为当前目录是你启动可执行文件时。



安装时的当前目录,当你从自定义操作中启动.exe时(一个不好的方式,如果你看起来很糟糕,那么它应该是可选的)您希望这种情况发生!)与当前目录的不同之处在于您用于启动应用程序的快捷方式中指定的内容。在快捷方式中,开始目录指定启动快捷方式目标时应将当前目录设置为什么。



现在,这也意味着什么是你的应用程序以这样的方式编码,它总是假定当前目录是你认为的。这意味着你的代码正在使用所有内容的相对路径,而不是为它正在使用的文件生成完全限定的路径。



您的应用甚至可以更改当前目录的内容当它在运行。在不知情的情况下执行此操作的简单方法是显示OpenFile对话框,用户导航到其他文件夹以查找他/她希望您的应用程序打开的文件。用户刚刚更改了应用程序中的当前目录,您甚至都不知道。



始终构建并使用应用程序使用的所有文件的完全限定路径。这些文件路径以驱动器号C:或UNC路径\\server\share \ directory开头。
The problem is probably coming down to what the "current directory" is when you launch the executable.

The "current directory" at install-time, and when you launch the .exe from your custom action (A BAD IDEA BY THE WAY, it shjould be OPTIONAL if you want this to happen!) is different from the "current directory" is as specified in the shortcut you use to launch the app. In the shortcut, the "Start In" directory specifies what the "current directory" should be set to when the shortcut target is launched.

Now, what this also means is that your app is coded in such ways that it always assumes the current directory is what YOU think it is. It means your code is using relative paths for everything instead of generating fully qualified paths to the files it's using.

Your app can even change what the "current directory" is while it's running. An easy way to do that without knowing your doing it is to show an OpenFile dialog and the user navigates to some other folder to find a file he/she wants your app to open. The user just changed the current directory on your app and you didn't even know it.

ALWAYS build and use fully qualified paths to all files your app uses. These are filepaths that start with a drive letter "C:" or a UNC path, "\\server\share\directory".


这篇关于安装后找不到System.io.filenotfoundexception图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆