安装 ClickOnce 应用程序时出错

Error when installing ClickOnce application

今天,每次用户尝试安装应用程序时,我都开始收到错误消息,我不知道为什么在几个月的部署问题为 0 之后我会收到此消息,我没有更改与项目属性相关的任何内容,所有修改都已完成代码相关。

这是错误日志

PLATFORM VERSION INFO Windows : 10.0.15063.0 (Win32NT) Common Language Runtime : 4.0.30319.42000 System.Deployment.dll : 4.7.2046.0 built by: NET47REL1 clr.dll : 4.7.2101.1 built by: NET47REL1LAST dfdll.dll : 4.7.2046.0 built by: NET47REL1 dfshim.dll : 10.0.15063.0 (WinBuild.160101.0800)

SOURCES Deployment url : file:///Y:/RE/RentaEquipos.application Deployment Provider url : file://svrre/Repository/RE/RentaEquipos.application Application url : file://svrre/Repository/RE/Application%20Files/RentaEquipos_2017_07_10_8/RentaEquipos.exe.manifest

IDENTITIES Deployment Identity : RentaEquipos.application, Version=2017.7.10.8, Culture=es-CR, PublicKeyToken=0000000000000000, processorArchitecture=x86

APPLICATION SUMMARY * Installable application.

ERROR SUMMARY Below is a summary of the errors, details of these errors are listed later in the log. * Activation of Y:\RE\RentaEquipos.application resulted in exception. Following failure messages were detected: + Specified cast is not valid.

COMPONENT STORE TRANSACTION FAILURE SUMMARY No transaction error was detected.

WARNINGS * The manifest for this application does not have a signature. Signature validation will be ignored. * The manifest for this application does not have a signature. Signature validation will be ignored. * The manifest for this application does not have a signature. Signature validation will be ignored.

OPERATION PROGRESS STATUS * [26/7/2017 11:23:16] : Activation of Y:\RE\RentaEquipos.application has started. * [26/7/2017 11:23:16] : Processing of deployment manifest has successfully completed. * [26/7/2017 11:23:16] : Installation of the application has started.

ERROR DETAILS Following errors were detected during this operation. * [26/7/2017 11:23:16] System.InvalidCastException - Specified cast is not valid. - Source: System.Deployment - Stack trace: at System.Deployment.Application.DownloadManager.VerifyRequestedPrivilegesSupport(String requestedExecutionLevel) at System.Deployment.Application.DownloadManager.DownloadApplicationManifest(AssemblyManifest deploymentManifest, String targetDir, Uri deploymentUri, > IDownloadNotification notification, DownloadOptions options, Uri& appSourceUri, String& appManifestPath) 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, 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)

COMPONENT STORE TRANSACTION DETAILS No transaction information is available.

DownloadManager.VerifyRequestedPrivilegesSupport 方法正在抛出 InvalidCastException。不幸的是,class 的代码在 ReferenceSource, but when System.Deployment.dll is decompiled 上不可用,罪魁祸首很明显。反编译后的方法是这样的:

private static void VerifyRequestedPrivilegesSupport(string requestedExecutionLevel)
{
  Logger.AddMethodCall("VerifyRequestedPrivilegesSupport(" + requestedExecutionLevel + ") called.");
  if (!PlatformSpecific.OnVistaOrAbove)
    return;
  bool flag = false;
  RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Policies\System");
  if (registryKey != null && registryKey.GetValue("EnableLUA") != null)
  {
    Logger.AddInternalState("LUA policy key = " + registryKey.Name);
    if ((int) registryKey.GetValue("EnableLUA") != 0)
    {
      flag = true;
      Logger.AddInternalState("LUA is enabled.");
    }
  }
  if (flag && (string.Compare(requestedExecutionLevel, "requireAdministrator", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(requestedExecutionLevel, "highestAvailable", StringComparison.OrdinalIgnoreCase) == 0))
    throw new InvalidDeploymentException(ExceptionTypes.UnsupportedElevetaionRequest, string.Format((IFormatProvider) CultureInfo.CurrentUICulture, Resources.GetString("Ex_ManifestExecutionLevelNotSupported"), new object[0]));
}

抛出异常的行应该是这一行:

if ((int) registryKey.GetValue("EnableLUA") != 0)

代码从 windows 注册表中读取注册表项 \HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersio‌​n\Policies\System。要抛出该异常,键必须存在并且它必须具有 EnableLUA 值,但该值的类型必须不是整数。您需要在出现错误的计算机上 运行 RegEdit.exe,导航到注册表中的该键,并检查该值以查看它是什么。它应该在该值的 Type 列中显示 REG_DWORD。如果不是,请将其删除并重新添加正确的类型。