I have a WPF application deployed using ClickOnce. It has one custom file association set with it that can open and be opened in the application if that file type is opened. This has been working great, then all of a sudden during an update users started receiving an "Application Could Not Be Started" errors.
Looking into the error details I can see this:
ERROR DETAILS
Following errors were detected during this operation.
* [12/8/2020 3:34:54 PM] System.UnauthorizedAccessException
- Attempted to perform an unauthorized operation.
- Source: mscorlib
- Stack trace:
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind)
at System.Deployment.Application.ShellExposure.AddFileAssociation(FileAssociation fileAssociation, DefinitionIdentity subId, Uri deploymentProviderUri)
at System.Deployment.Application.ShellExposure.AddShellExtensions(DefinitionIdentity subId, Uri deploymentProviderUri, AssemblyManifest appManifest)
at System.Deployment.Application.ShellExposure.UpdateShellExtensions(SubscriptionState subState, ShellExposureInformation& shellExposureInformation)
at System.Deployment.Application.ShellExposure.UpdateSubscriptionShellExposure(SubscriptionState subState)
at System.Deployment.Application.SubscriptionStore.CommitApplication(SubscriptionState& subState, CommitApplicationParams commitParams)
at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl, Uri& deploymentUri)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivationWithRetry(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivationWithRetry(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
I determined it was the file association as that is the only thing touching the registry by ClickOnce AFIK. After removing it, the issue went away, but now the program has no file extensions. I've tried installing with elevated permissions, but that hasn't fixed the issue either. Adding the extension back caused the issue to return. We didn't touch any of the underlying file association or startup logic on this update so what the heck would be causing this issue?
Has anyone experienced this working with ClickOnce and file associations?
Edit: Using VS2017's Publish->Options to create the associations (which drops the info into the .csproj file).
<ItemGroup>
<FileAssociation Include=".simsp">
<Visible>False</Visible>
<Description>My Description</Description>
<Progid>MyProgram.Proposal</Progid>
<DefaultIcon>Proposal.ico</DefaultIcon>
</FileAssociation>
</ItemGroup>
Also, after uninstalling and removing AppData files related to the app, the app installed on one machine fine, but not the other under the same user account (we use file sync to replicate desktops). This is confusing as I am not sure why the install would fail during Registry entry if it's an issue in the AppData files located in the Users path.
EDIT 3: The issue seems to occur randomly, but we noticed it occurs when a file is opened, causing the ClickOnce app to open and update. Thus far, the issue seems isolated to user using file sync, replicated desktops who have mutliple workstations.
Best practices to work around this? It may just be a ClickOnce limitation.