Monday, March 10, 2008

ClickOnce Error: DeploymentDownloadException File Already Exists

ClickOnce is OnceAgain acting up. My project was building and publishing fine, but when I went to run the application, it would fail while downloading the new version. The complete stack trace of the error is:

System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
- Downloading file://[snip].dll.deploy did not succeed.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
at System.Deployment.Application.DownloadManager.DownloadDependencies(SubscriptionState subState, AssemblyManifest deployManifest, AssemblyManifest appManifest, Uri sourceUriBase, String targetDirectory, String group, IDownloadNotification notification, DownloadOptions options)
at System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension)
at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
--- Inner Exception ---
System.IO.IOException
- The file 'C:\Users\[username]\AppData\Local\Temp\Deployment\[snip].dll' already exists.
- Source: mscorlib
- Stack trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)

I immediately suspected some recent changes involving the deployment settings. A coworker added some project references to the solution for this application. This resulted in some strange compile errors that basically said the referenced assemblies had to be signed to be marked as prerequisites to the project. When checked the application files (project properties -> publish tab -> application files button) and the assemblies were set to "Include (Auto)" like pretty much everything else. I changed them to "Include" and the application built fine.

The deployment error above was for one of those assemblies. On a whim I decided to create a new "Download Group" in the application files dialog. That seemed to solve the problem. Why that solved this problem, I don't know.

As much as I like ClickOnce, it seems to be getting more and more finicky.

ClickOnce Error: The signer's certificate is not valid for signing.

Today when I was trying to publish a ClickOnce application that we use internally, I got the following error:

The signer's certificate is not valid for signing.

After looking around and some searching on Google, I was able to find the problem and resolve it. My problem was that the certificate I had been using to sign the ClickOnce deployments had expired. You can view the status of your certificate in Visual Studio, in the project properties window, on the signing tab.

To fix the problem just create a new certificate by clicking the button titled "Create Test Certificate..." It will prompt you for a password, which I left blank. Once you have the new certificate created you should be able to publish once again.