简体   繁体   English

C#应用程序无法在其他计算机上运行

[英]C# app doesn't work in other computers

Why does my app compiled with C# not work on other computers? 为什么用C#编译的应用程序不能在其他计算机上运行?

I have the .Net Framework 4.0 already installed. 我已经安装了.Net Framework 4.0。

When I open my .exe on another computer, I get the error: 在另一台计算机上打开.exe时,出现错误消息:

ERROR SIGNATURE:

    Event Type: clr20r3  
    P1:         myapp.exe 
    P2:         1.0.0.0
    P3:         502051f 
    P4:         myapp 
    P5:         1.0.0.0 
    P6:         502051f 
    P7:         2 
    P8:         6 
    P9:         System.IO.FileNotFoundException

A system.io.filenotfoundexception usually means your program tried to open a file that wasn't there. system.io.filenotfoundexception通常意味着您的程序试图打开一个不存在的文件。 It is likely that your program is trying to access some file using a path or filename that doesn't exist or is in a different location on other computers. 您的程序可能正在尝试使用其他计算机上不存在或位于其他位置的路径或文件名来访问某些文件。 Without knowing what myapp.exe is supposed to do, I can't answer any further. 不知道myapp.exe应该做什么,我无法再回答了。

Your solution is probably to re-write your app so that it handles that exception better in some way, such as by checking for the file's existence before trying to open it. 您的解决方案可能是重新编写您的应用程序,以便它以某种方式更好地处理该异常,例如通过在尝试打开文件之前检查文件的存在。

It sounds to me like a case of missing references. 在我看来,这似乎是缺少参考文献的情况。 Check your references from the solution explorer or go into bin/debug or bin/release (depending on your configuration) and make sure to copy all the dlls or exes that your project depends on 从解决方案资源管理器中检查您的引用,或进入bin / debug或bin / release(取决于您的配置),并确保复制项目所依赖的所有dll或exe。

Most likely the app is trying to load an assembly and is failing to find it 该应用很可能尝试加载程序集,但找不到它

A little off topic but ideally with any application you want to add some 'unhandled' exception handling to write to a log file or the event log so that you can capture more of the exception stack. 稍微有些偏离主题,但理想情况下,对于要添加一些“未处理”异常处理以写入日志文件或事件日志的任何应用程序,以便可以捕获更多异常堆栈。

Often you only get the last exception message and you also don't see the call stack 通常,您只会收到最后一条异常消息,而您也看不到调用堆栈

You can roll up exceptions quite easily using something like this: 您可以使用以下类似方法轻松汇总异常:

string RollupException(Exception ex)
{
    StringBuilder sb = new StringBuilder();

    sb.Append(ex.Message);

    while(ex.InnerException != null) 
    {
         sb.Append(Environment.Newline);
         sb.Append(ex.Message);
         ex = ex.InnerException;
    }

    return sb.ToString();
}

You can also use the EventLog class to write to the event log. 您也可以使用EventLog类写入事件日志。

Info here: 此处的信息:

http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx http://msdn.microsoft.com/zh-CN/library/system.diagnostics.eventlog.aspx

Check out the examples - remember to register an event source first! 查看示例-请记住首先注册事件源!

It looks like your program's missing a DLL (or the DLL's been misplaced): 看来您的程序缺少DLL(或DLL放错了位置):

http://social.msdn.microsoft.com/Forums/pl-PL/clr/thread/782217a8-46bd-4371-9915-28655d9b2c2f http://social.msdn.microsoft.com/Forums/pl-PL/clr/thread/782217a8-46bd-4371-9915-28655d9b2c2f

Deciphering the .NET clr20r3 exception parameters P1..P10 解密.NET clr20r3异常参数P1..P10

A simple way around this would be to create a setup project - this will then bundle your project's dependencies into an install file. 解决此问题的一种简单方法是创建一个安装项目-然后将您项目的依赖项捆绑到一个安装文件中。 I don't think that option's available if you're on Visual Studio Express edition though. 但是,如果您使用的是Visual Studio Express版本,我认为该选项不可用。 . .

http://www.dreamincode.net/forums/topic/58021-deploying-ac%23-application-visual-studio-setup-project/ http://www.dreamincode.net/forums/topic/58021-deploying-ac%23-application-visual-studio-setup-project/

If you're pretty sure it's a .net framework that's missing, the following tool will show you what's on your machine / your client's, so you can figure out what's missing: 如果您确定它缺少.net框架,则以下工具将向您显示计算机上/客户端上的内容,以便您找出丢失的内容:

http://www.asoft.be/prod_netver.html http://www.asoft.be/prod_netver.html

Hope that helps. 希望能有所帮助。

I had exactly the same problem and like Joao eventually found it was caused by the Windows Forms LineShape. 我遇到了完全相同的问题,就像Joao最终发现的那样,它是由Windows Forms LineShape引起的。 This adds the Microsoft.VisualBasic.PowerPacks reference to your project. 这会将Microsoft.VisualBasic.PowerPacks引用添加到您的项目。 When you then run it on a system that doesn't have the PowerPacks installed you just get that unhelpful System.IO.FileNotFoundException error with no clue as to which file is missing. 然后,在没有安装PowerPack的系统上运行它时,您只会得到该无用的System.IO.FileNotFoundException错误,并且不知道缺少哪个文件。

Yes I know this should get fixed up if you go the trouble of making a proper distribution setup which will prompt the user to install ..., etc, etc. But I just want to be able simply to copy my EXE to another system. 是的,我知道如果您麻烦进行正确的发行版设置会提示用户安装...等,则应该解决此问题。但是我只希望能够将我的EXE复制到另一个系统。

To solve: remove any LineShapes from your form and then remove the refences to VisualBasic and VisualBasic.PowerPacks in your references. 解决方案:从表单中删除任何LineShapes,然后在引用中删除对VisualBasic和VisualBasic.PowerPacks的引用。

David 大卫

[Using VS2008 SP] [使用VS2008 SP]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 安装后,带有 Access 数据库 (accdb) 的 c# windows 应用程序在其他计算机上不起作用 - The c# windows app with Access database (accdb) doesn't work on other computers after installation 我将 c# windows 应用程序与 Access 数据库 (accdb) 连接,但该应用程序在其他计算机上不起作用 - I connected c# windows app with Access database (accdb) but the application doesn't work on other computers WPF应用程序无法在其他计算机上运行 - WPF application doesn't work in other computers C#应用程序无法在XP上运行 - c# app doesn't work on XP 多人游戏不适用于其他计算机。 只在同一个 - Multiplayer doesn't work with other computers. Only on the same one C#Winform应用程序无法在其他计算机上运行(神秘的启动时) - C# Winform App Not Working On Other Computers (Mysterious Hang On Startup) app.config 上的 C# ConnectionString 在其他计算机上不起作用 - C# ConnectionString on app.config not working on other computers c# unity 中的音乐播放器不适用于其他场景 - Music player in c# unity doesn't work with other scenes C# 程序在其他计算机上不起作用 - C# Program doesn't work on other computer 无法在某些 Windows 7 计算机上打开我的 c# 应用程序 - Can´t open my c# app on some Windows 7 computers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM