Gustav Bok Gustav Bok - 1 year ago 119
C# Question

ClickOnce CheckForUpdate() returns null after a while

I have a problem with a ClickOnce application, when I call

for a while it works, and I the restart system works perfectly. After about one hour it starts crashing. I'm running this on a seperate thread and the ClickOnce application is on our local network.

The error code:

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()

Here is the method:

private void RestartUpdate()
bool running = true;
while (running)
if (ApplicationDeployment.IsNetworkDeployed)
ApplicationDeployment updateCheck = ApplicationDeployment.CurrentDeployment;
bool newUpdate = updateCheck.CheckForUpdate(); **<---- Problem**
if (newUpdate == true)
updateCheck.UpdateCompleted +=
new AsyncCompletedEventHandler(
catch (Exception e)

Do you have any clue why this is happening?


Found an answer from James Miles who seems to bypass the click-once deployment API entirely when checking for updates:

//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);

Answer Source

I went for the solution that bypasses the 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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download