.net 如何找出导致通用“应用程序无法启动”的原因。联系应用程序供应商。ClickOnce 错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20518112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find out what causes the generic 'Application cannot be started. Contact the application vendor.' ClickOnce errors?
提问by Sheridan
I have a .NET application that is published using ClickOnce. For the most part, everything works well with this procedure, but every once in a while, a user will get an error that throws up the message shown below instead of opening the program:
我有一个使用 ClickOnce 发布的 .NET 应用程序。在大多数情况下,这个过程一切正常,但每隔一段时间,用户就会收到一个错误,抛出如下所示的消息,而不是打开程序:
Application cannot be started. Contact the application vendor.
应用程序无法启动。联系应用程序供应商。


I found the Troubleshooting Specific Errors in ClickOnce Deploymentspage on MSDN which states (in the Additional Errors section):
我在 MSDN 上的ClickOnce 部署页面中找到了故障排除特定错误,其中指出(在附加错误部分):
Error message
Application cannot be started. Contact the application publisher.
Cannot start the application. Contact the application vendor for assistance.
Description
These are generic error messages that occur when the application cannot be started, and no other specific reason can be found. Frequently this means that the application is somehow corrupted, or that the ClickOnce store is corrupted.
错误信息
应用程序无法启动。联系应用程序发布者。
无法启动应用程序。联系应用程序供应商寻求帮助。
描述
这些是应用程序无法启动时出现的一般错误消息,并且找不到其他特定原因。这通常意味着应用程序以某种方式损坏,或者 ClickOnce 存储已损坏。
While it's not an exact match for the error message that is displayed for this problem, I think that it is close enough to fit into the above category of errors. Now the fix for this problem is to simply delete all of the ClickOnce user settings that are stored in...
虽然它与针对此问题显示的错误消息不完全匹配,但我认为它足以适应上述错误类别。现在,解决此问题的方法是简单地删除存储在...中的所有 ClickOnce 用户设置。
C:\Users\USERNAME\AppData\Local\Apps.0
... so the problem is bearable, but my question is this:
......所以这个问题是可以忍受的,但我的问题是:
What can I do to find out what is causing these generic errors so that I can stop them from occurring?
我能做些什么来找出导致这些一般错误的原因,以便我可以阻止它们发生?
采纳答案by avs099
2 things:
2件事:
If you click that "Details..." button you will get a log file which, usually, shows what the error is (it could be broken manifest file on server, etc).
If you say deleting local settings help, then it might be that user.config file gets corrupted. We had this issue in our app - and I was not able to find out WHY (my guess was that I was writing to
Properties.Settingstoo often but I'm not sure). Anyway, here is my workaround for it:public static void Main() { if (ApplicationDeployment.IsNetworkDeployed == true) { try { ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); } catch (ConfigurationErrorsException ex) { string filename = ex.Filename; _logger.Error(ex, "Cannot open config file"); if (File.Exists(filename) == true) { _logger.Error("Config file {0} content:\n{1}", filename, File.ReadAllText(filename)); File.Delete(filename); _logger.Error("Config file deleted"); Properties.Settings.Default.Upgrade(); // Properties.Settings.Default.Reload(); // you could optionally restart the app instead } else { _logger.Error("Config file {0} does not exist", filename); } } } // code continues... }basically I try to read settings, if any error - log the broken file's content, delete it and continue.
如果您单击“详细信息...”按钮,您将获得一个日志文件,该文件通常显示错误是什么(它可能是服务器上的清单文件损坏等)。
如果您说删除本地设置帮助,则可能是 user.config 文件已损坏。我们在我们的应用程序中遇到了这个问题 - 我无法找出原因(我猜是我写信
Properties.Settings太频繁了,但我不确定)。无论如何,这是我的解决方法:public static void Main() { if (ApplicationDeployment.IsNetworkDeployed == true) { try { ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); } catch (ConfigurationErrorsException ex) { string filename = ex.Filename; _logger.Error(ex, "Cannot open config file"); if (File.Exists(filename) == true) { _logger.Error("Config file {0} content:\n{1}", filename, File.ReadAllText(filename)); File.Delete(filename); _logger.Error("Config file deleted"); Properties.Settings.Default.Upgrade(); // Properties.Settings.Default.Reload(); // you could optionally restart the app instead } else { _logger.Error("Config file {0} does not exist", filename); } } } // code continues... }基本上我尝试读取设置,如果有任何错误 - 记录损坏文件的内容,删除它并继续。
回答by Dan Cappannari
If your project is 64 bit and you try to copy it to \windows\system32, you get this error. Moving the .exe to \windows\syswow64 fixes the problem.
如果您的项目是 64 位并且您尝试将其复制到 \windows\system32,则会出现此错误。将 .exe 移动到 \windows\syswow64 可以解决此问题。

