我遇到了ClickOnce应用程序的问题,当我调用它CheckForUpdate()
一段时间后,我的重启系统工作正常。大约一个小时后,它开始崩溃。我在一个单独的线程上运行它,ClickOnce应用程序在我们的本地网络上。
错误代码:
System.Deployment.Application.DeploymentException:此部署的应用程序已安装,具有不同的应用程序标识。在System.Deployment.Application.SubscriptionStore.CheckAndReferenceApplication(SubscriptionState subState,DefinitionAppId appId,Int64 transactionId) 在System.Deployment.Application.DeploymentManager.BindCore(布尔阻塞,TempFile和tempDeploy,TempDirectory& tempAppDir,FileStream& refTransaction,String& productName) 在System.Deployment.Application.DeploymentManager.Bind() 在System.Deployment.Application.ApplicationDeployment.CheckForDetailedUpdate(Boolean persistUpdateCheckResult) 在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的答案,他在检查更新时似乎完全绕过了Click-once部署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);
答案 0 :(得分:0)
我选择绕过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();
}