.net - 如何找出导致通用 'Application cannot be started. Contact the application vendor.' ClickOnce 错误的原因?

标签 .net clickonce

我有一个使用 ClickOnce 发布的 .NET 应用程序。在大多数情况下,此过程一切正常,但每隔一段时间,用户就会收到一个错误,抛出如下所示的消息,而不是打开程序:

Application cannot be started. Contact the application vendor.

enter image description here

我找到了Troubleshooting Specific Errors in ClickOnce Deployments MSDN 页面上指出(在“其他错误”部分):

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 用户设置。

C:\Users\USERNAME\AppData\Local\Apps\2.0  

...所以这个问题是可以忍受的,但我的问题是这样的:

我该如何找出导致这些一般错误的原因,以便阻止它们发生?

最佳答案

两件事:

  1. 如果您单击“详细信息...”按钮,您将获得一个日志文件,该文件通常显示错误是什么(可能是服务器上的 list 文件损坏等)。

  2. 如果您说删除本地设置有帮助,那么可能是 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...
    }
    

    基本上,我会尝试读取设置,如果有任何错误 - 记录损坏文件的内容,将其删除并继续。

关于.net - 如何找出导致通用 'Application cannot be started. Contact the application vendor.' ClickOnce 错误的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20518112/

相关文章:

c# - ClickOnce 部署 "Activation failed"FileNotFoundException

C# WinForm 在安装时设置 ConnectionString 和 Entity Framework

c# - 安装过程中如何创建文件夹?

c# - 在 web.config 中使用 <rewrite> 重定向

.net - 在 .NET 框架中强制使用英语语言异常

.net - vb.net dataTable/DataGridView 搜索/排序

deployment - 部署后出现ClickOnce错误-计算出的哈希值与 list 中指定的值不同

.net - 单击一次的Google Chrome扩展程序?

wpf - 错误: Failed to connect while Publishing Click Once Application Wpf

c# - 获取目录时出现 System.UnauthorizedAccessException