VSTOでSystem.Security.SecurityExceptionが出た

作成日:
エラー

Visual Studio 2015 でExcelのCOMアドインを作ってデバッグしていると突然エラーが出るようになってデバッグできなくなりました。インストーラ―でインストールした物もExcelを開いた時点で画像のエラーが出ます。

Microsoft Office カスタマイズ インストールエラー

Office のカスタマイズのインストール

インストール中にエラーが発生しました。

このアプリケーションのカスタマイズされた機能は動作しません。XXX の配置マニフェストに署名するときに使用された証明書が信頼されていないか、アプリケーションが信頼された場所にありません。詳細については管理者に問い合わせてください。

詳細は以下のような具合です。

************** 例外テキスト **************
System.Security.SecurityException: このアプリケーションのカスタマイズされた機能は動作しません。XXX の配置マニフェストに署名するときに使用された証明書が信頼されていないか、アプリケーションが信頼された場所にありません。詳細については管理者に問い合わせてください。
   場所 Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInTrustEvaluator.VerifyTrustPromptKeyInternal(ClickOnceTrustPromptKeyValue promptKeyValue, DeploymentSignatureInformation signatureInformation, String productName, TrustStatus status)
   場所 Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInTrustEvaluator.VerifyTrustUsingPromptKey(Uri manifest, DeploymentSignatureInformation signatureInformation, String productName, TrustStatus status)
   場所 Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.ProcessSHA2Manifest(ActivationContext context, DeploymentSignatureInformation signatureInformation, PermissionSet permissionsRequested, Uri manifest, ManifestSignatureInformationCollection signatures, AddInInstallationStatus installState, TrustStatus sha256TrustStatus, X509Certificate2 sha256PublisherCert)
   場所 Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.VerifySecurity(ActivationContext context, Uri manifest, AddInInstallationStatus installState)
   場所 Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()
失敗したアセンブリのゾーン:
MyComputer
対策

対策ですが、結論からいうと、インターネットオプション → コンテンツタブ → 証明書 の「信頼された発行元」にVSTO プロジェクトの「ClickOnceマニフェストに署名」で署名したコードサイニング証明書を追加することで解決しました。いつの間にかこの一覧から証明書が削除されたということでしょうか。。

関連記事