ClickOnce CheckForUpdate() returns 一段时间后为空

ClickOnce CheckForUpdate() returns null after a while

我的 ClickOnce 应用程序有问题,当我调用 CheckForUpdate() 一段时间后它可以正常工作,并且我重新启动系统后工作正常。大约一小时后,它开始崩溃。我在一个单独的线程上 运行 并且 ClickOnce 应用程序在我们的本地网络上。

错误代码:

System.Deployment.Application.DeploymentException: An application for this deployment is already installed with a different application identity. at System.Deployment.Application.SubscriptionStore.CheckAndReferenceApplication(SubscriptionState subState, DefinitionAppId appId, Int64 transactionId) at System.Deployment.Application.DeploymentManager.BindCore(Boolean blocking, TempFile& tempDeploy, TempDirectory& tempAppDir, FileStream& refTransaction, String& productName) at System.Deployment.Application.DeploymentManager.Bind() at System.Deployment.Application.ApplicationDeployment.CheckForDetailedUpdate(Boolean persistUpdateCheckResult) at System.Deployment.Application.ApplicationDeployment.CheckForUpdate()

方法如下:

private void RestartUpdate()
{
    bool running = true;
    while (running)
    {
        Thread.Sleep(5000);
        try
        {
            if (!RESTARTING)
            {
                if (ApplicationDeployment.IsNetworkDeployed)
                {
                    ApplicationDeployment updateCheck = ApplicationDeployment.CurrentDeployment;
                    bool newUpdate = updateCheck.CheckForUpdate(); **<---- Problem**
                    if (newUpdate == true)
                    {
                        RESTARTING = true;
                        updateCheck.UpdateCompleted +=
                        new AsyncCompletedEventHandler(
                        Deployment_UpdateCompleted);
                        updateCheck.UpdateAsync();                               
                    }
                }
            }
        }
        catch (Exception e)
        {
            SendErrorMessageToServer(e.ToString());
        }
    }
}

你知道为什么会这样吗?

编辑:

从 James Miles 那里找到了答案,他似乎在检查更新时完全绕过了单击一次部署 API:

//Used to use the Clickonce API but we've uncovered a pretty serious bug which results in a COMException and the loss of ability
//to check for updates. So until this is fixed, we're resorting to a very lo-fi way of checking for an update.
var manifestFile = new WebClient().DownloadString(updateLocation);
var xdoc = XDocument.Parse(manifestFile);
XNamespace nsSys = "urn:schemas-microsoft-com:asm.v1";
var version = new Version(xdoc.Descendants(nsSys + "assemblyIdentity").First().Attribute("version").Value);

我寻求绕过 OneClick API 的解决方案。

string manifestFile = new WebClient().DownloadString(@"\*\*.application");
XDocument xdoc = XDocument.Parse(manifestFile);
XNamespace nsSys = "urn:schemas-microsoft-com:asm.v1";
Version versionNew = new Version(xdoc.Descendants(nsSys + "assemblyIdentity").First().Attribute("version").Value);
int result = applicationDeplayment.CurrentVersion.CompareTo(versionNew);
if (result < 0)
{
   applicationDeplayment.UpdateAsync();
}