简体   繁体   中英

my windows forms application throws filenotfoundexception when run on another machine

I have created a windows forms application using vs2008. when i copy the bin folder over to another machine and try to run it the applicaiton throws a filenotfoundexception error. Ive looked at the references files used in the project and each file points to either

  • c:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727...
  • c:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.5...
  • c:\\Program Files\\Common Files\\Microsoft Shared\\Visual Basic Power Packs\\1.1...

i have verified that these directories exist on the other machines that cause the error. the two machines that i have tried it on and that throw there error are

Windows XP WITHOUT VS2008 installed and Windows 7 with VS2008 installed

I tried on two machine that DID work which are

Windows XP with VS2008 and and my development machine Windows 7 with VS2008

Could anyone provide me with some insight on this issue Thanks

if you have all the global assemblies registered then check in your code if you are reading/opening some file with absolute path which is raising exception.

Say you had a file c:\\abc.txt which you were opening. This file might be available on developer machine but not in other test machines. You may want to check the File.Open function calls in your program.

which file not found, try to catch the exception and log the exception details which file is not found. Also you say installing VS2008, the app works, then just try installing VS2008 redistributable runtime libraries. It needed for webbrowser and other api.

maybe use

Dim rootPath As String = Server.MapPath("~")

and a relative path(?)

Make sure you wrap the entirety of your Main function guts in a try catch(). Then you can show the message to find out what assembly is missing. Once you do that, go to that assembly in the references, and in it's properties set CopyLocal = true.

Ex:

        [STAThread]
    static void Main()
    {
        try
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MyForm());
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

使用sysinternals的进程监视器-这将使您看到您的应用尝试打开哪些文件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM