Solving the age-old ClickOnce VSTO System.ArgumentException Value does not fall within the expected range error
I recently encountered a situation in which I updated and upgraded a ClickOnce VSTO application. I was able to build the application with only minor warnings. Uninstalling the old version and installing the new version worked fine on my computer, but errored when installing on my coworker’s devices.
************** Exception Text **************
System.ArgumentException: Value does not fall within the expected range.
at System.Deployment.Internal.Isolation.IActContext.ApplicationBasePath(UInt32 Flags, String& ApplicationPath)
at System.ActivationContext.get_ApplicationDirectory()
at System.AppDomainSetup..ctor(ActivationArguments activationArguments)
at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.CreateAppDomainSetup(ActivationContext context, Uri deploymentManifestUri, AddInInstallationStatus installStatus)
at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()
For SEO purposes: VSTO System.ArgumentException: Value does not fall within the expected range.
The internet recommended I do the following:
rundll32 %windir%\system32\dfshim.dll CleanOnlineAppCache
del C:\users\USER\AppData\Local\Apps\2.0\
This alone unfortunately did not resolve my issue.
After hours of debugging, I learned that C# projects do not automatically remove old dependencies from properties.csproj
files. As a result, there could be overlapping versions of the same dependency, which would cause the ClickOnce installation to fail.
I manually edited my properties.csproj
and removed the specific versions of libraries that were no longer needed for my project. These libraries could also be identified by looking at the dependency-related warnings when reading the debug build output from the C# project in Visual Studio.
One of the problematic package references within the properties.csproj
is shown below. It was formatted slightly differently than the other package references, although that may have just been a coincidence.
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
Hopefully this post helps resolve your issue!
Massive shoutout to this StackOverflow post for leading me down the right path to solving this problem: https://stackoverflow.com/a/39068355