gpt4 book ai didi

c# - ClickOnce CheckForUpdate() 一段时间后返回 null

转载 作者:太空宇宙 更新时间:2023-11-03 15:11:56 26 4
gpt4 key购买 nike

我的 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();
}

关于c# - ClickOnce CheckForUpdate() 一段时间后返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40806916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com