wpf VS 2017:设置了安全调试选项,但它需要不可用的 Visual Studio 托管进程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44821734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 14:06:51  来源:igfitidea点击:

VS 2017 : The security debugging option is set but it requires the Visual Studio hosting process which is unavailable

c#.netwpfvisual-studiovisual-studio-2017

提问by StevenPF

My solution (which contains a dozen projects) works perfectly in Visual Studio 2013.

我的解决方案(包含十几个项目)在 Visual Studio 2013 中完美运行。

In Visual Studio 2017, I can open the solution and compile it.

在 Visual Studio 2017 中,我可以打开解决方案并编译它。

But if I start the debug, I systematically get this error message:

但是如果我开始调试,我会系统地收到这个错误信息:

The security debugging option is set but it requires the Visual Studio hosting process which is unavailable in this debugging configuration.The security debugging option will be disabled. This option may be re-enabled in the Security property page. The debugging session will continue without security debugging

设置了安全调试选项,但它需要在此调试配置中不可用的 Visual Studio 托管进程。安全调试选项将被禁用。可以在安全属性页中重新启用此选项。调试会话将在没有安全调试的情况下继续

enter image description here

在此处输入图片说明

And then, nothing happens. Nothing starts.

然后,什么也没有发生。什么都没有开始。

For information, this is a solution with multiple startup projects (including a WPF project).

有关信息,这是具有多个启动项目(包括 WPF 项目)的解决方案。

Edit :By disabling the option "Enable ClickOnce security settings" under Project -> Properties -> Security tab, it works.

编辑:通过禁用项目 -> 属性 -> 安全选项卡下的“启用 ClickOnce 安全设置”选项,它可以工作。

回答by Scott O.

In case it helps anyone else - I have the same scenario - a multiple startup solution that includes a client that will be deployed with ClickOnce. To eliminate the problem that the client doesn't start after getting the Security Settings dialog, I moved it higher in the list in the startup projects dialog. If the client project is above the server project in the list, no error, everything debugs. If the client project is below the server project, then I get the error and the client never opens. This doesn't exactly SOLVE the problem but is a perfectly adequate workaround for me.

如果它对其他人有帮助 - 我有相同的场景 - 一个多启动解决方案,其中包括一个将使用 ClickOnce 部署的客户端。为了消除客户端在获得安全设置对话框后无法启动的问题,我将其在启动项目对话框的列表中移到更高的位置。如果客户端项目在列表中的服务器项目之上,则没有错误,一切都在调试。如果客户端项目低于服务器项目,那么我收到错误并且客户端永远不会打开。这并不能完全解决问题,但对我来说是一个完全足够的解决方法。

EDIT: You might need to close and reopen your Visual Studio for this workaround to be effective.

编辑:您可能需要关闭并重新打开 Visual Studio 才能使此变通方法生效。

回答by ATD

This solved my issue: https://social.msdn.microsoft.com/Forums/vstudio/en-US/3905f6ac-737b-420f-b312-3dd8e3676c35/getting-an-unexplained-securityexception?forum=wpf

这解决了我的问题:https: //social.msdn.microsoft.com/Forums/vstudio/en-US/3905f6ac-737b-420f-b312-3dd8e3676c35/getting-an-unexplained-securityexception?forum=wpf

Most likely, you have accidentally gotten the bit flipped to debug with ClickOnce security settings. Can you get the project properties for your app, go to the "Security" tab, and make sure to uncheck "Enable ClickOnce Security settings" or check the "This is a full trust application" radio button.

最有可能的是,您不小心使用 ClickOnce 安全设置进行了调试。您能否获取应用程序的项目属性,转到“安全”选项卡,并确保取消选中“启用 ClickOnce 安全设置”或选中“这是一个完全信任的应用程序”单选按钮。

回答by Morris S

I spent hours trying to figure out the issue, this resolved it.

我花了几个小时试图找出问题,这解决了它。

Go to Projct> Properties... > Build

转到项目>属性... >构建

Uncheck the checkbox Prefer 32-bit

取消选中“首选 32 位”复选框

enter image description here

在此处输入图片说明

回答by jon morgan

MS have removed the VS hosting process in VS2017 - see

MS 在 VS2017 中删除了 VS 托管进程 - 见

https://vslive.com/Blogs/News-and-Tips/2017/02/Debugging-Visual-Studio-2017-aims-to-speed-up-your-least-favorite-job.aspx

https://vslive.com/Blogs/News-and-Tips/2017/02/Debugging-Visual-Studio-2017-aims-to-speed-up-your-least-favorite-job.aspx

Because of this changing the EnableSecurityDebugging setting in the project user file to True simply results in the Error dialog appearing again at run-time.Clicking on OK in the dialog changes the user file setting back to False.

因此,将项目用户文件中的 EnableSecurityDebugging 设置更改为 True 只会导致运行时再次出现“错误”对话框。单击对话框中的“确定”会将用户文件设置更改回 False。

AFAIK there is no workaround although MS seem to be posting very frequent VS updates (latest is 15.3) In the meantime ClickOnce apps. will be unable to use the security debugging option.

AFAIK 没有解决方法,尽管 MS 似乎发布了非常频繁的 VS 更新(最新版本是 15.3),同时 ClickOnce 应用程序。将无法使用安全调试选项。

回答by Mats

This could likely be a glitch in some configuration file. The "Enable ClickOnce security settings" was already unmarked in the project settings but still this dialogue appeared every time the application was started. I did the following to get rid of this dialogue:

这可能是某些配置文件中的一个小故障。“启用 ClickOnce 安全设置”已在项目设置中取消标记,但每次启动应用程序时仍会出现此对话框。我做了以下事情来摆脱这个对话:

  1. Open the project->security setting page
  2. Mark "Enable ClickOnce security settings"
  3. Unmark "Enable ClickOnce security settings"
  4. Save the properties and start the application again
  1. 打开项目->安全设置页面
  2. 标记“启用 ClickOnce 安全设置”
  3. 取消标记“启用 ClickOnce 安全设置”
  4. 保存属性并再次启动应用程序

Properties

特性

回答by Mindy J. Leslie

I just had the same issue. Prefer 32-Bit was disabled. I looked in the Output Path and it was bin\Release.
I created a bin\debug path and set the Output Path to this. Resolved.

我只是有同样的问题。首选 32 位已禁用。我查看了输出路径,它是 bin\Release。
我创建了一个 bin\debug 路径并将输出路径设置为这个。解决。

回答by jon morgan

Here's a workaround that enabled me to debug my ClickOnce app.? in VS2017 without getting the error message "Unable to determine identity of caller" when accessing Isolated Storage. The workaround should also work in any situation that requires the ClickOnce security settings.

这是使我能够调试 ClickOnce 应用程序的解决方法。?在 VS2017 中访问隔离存储时没有收到错误消息“无法确定调用者的身份”。该解决方法也适用于需要 ClickOnce 安全设置的任何情况。

To recreate the settings that were previously generated when the Enable ClickOnce security settings on the Security tab of the project's properties was checked, do the following:

要重新创建之前在选中项目属性的“安全”选项卡上的“启用 ClickOnce”安全设置时生成的设置,请执行以下操作:

1.Uncheck Enable ClickOnce security settings on the Security tab of your project's properties

1.在项目属性的“安全”选项卡上取消选中“启用 ClickOnce 安全设置”

2.Add the following to your App.Config file if not already present

2.将以下内容添加到您的 App.Config 文件中(如果尚不存在)

<runtime>
  <NetFx40_LegacySecurityPolicyenabled="true"/>
</runtime>

3.Add a reference to ?Microsoft.Build.Tasks.v4.0 to your project

3.添加对 ?Microsoft.Build.Tasks.v4.0 的引用到您的项目

The code to recreate the ClickOnce settings can go anywhere, but the following sample Main method illustrates the general idea

重新创建 ClickOnce 设置的代码可以放在任何地方,但以下示例 Main 方法说明了总体思路

using System;
using System.Reflection;
using System.Runtime.Hosting;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
using System.Windows.Forms;
using Microsoft.Build.Tasks.Deployment.ManifestUtilities;


namespace SecurityDebuggingTest
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length > 0 && args[0] == "startui")
            {
                Application.Run(new Form1());
            }
            else
            {
                PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);
                string AppName = Assembly.GetEntryAssembly().GetName().Name;
                string AppExe = $"{AppName}.exe";
                string DebugSecurityZoneURL = $"{AppExe}.manifest";
                string AppManifestPath = $"{AppName}.application";
                string appType = "win32";
                AssemblyIdentity ca = AssemblyIdentity.FromManifest(AppManifestPath);
                string appIdentitySubString = $"Version={ca.Version}, Culture={ca.Culture}, PublicKeyToken={ca.PublicKeyToken}, ProcessorArchitecture={ca.ProcessorArchitecture}";
                string assemblyIdentity = $"http://tempuri.org/{AppManifestPath}#{AppManifestPath}, {appIdentitySubString}/{AppExe}, {appIdentitySubString},Type={appType}";
                System.ApplicationIdentity applicationIdentity = new System.ApplicationIdentity(assemblyIdentity);

                ApplicationTrust appTrust = new ApplicationTrust();
                appTrust.DefaultGrantSet = new PolicyStatement(permissions, PolicyStatementAttribute.Nothing);
                appTrust.IsApplicationTrustedToRun = true;
                appTrust.ApplicationIdentity = applicationIdentity;

                AppDomainSetup adSetup = new AppDomainSetup
                {
                    ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
                    ActivationArguments = new ActivationArguments(
                        ActivationContext.CreatePartialActivationContext(
                            applicationIdentity,
                            new string[] { AppManifestPath, DebugSecurityZoneURL })
                    ),
                    ApplicationTrust = appTrust
                };

                Evidence e = new Evidence();
                e.AddHostEvidence(appTrust);

                AppDomain a = AppDomain.CreateDomain("Internet Security Zone AppDomain", e, adSetup, permissions);
                a.ExecuteAssembly(AppExe, e, new string[] { "startui" });
            }
        }
    }
}

You may see the warning message about the VS Hosting process being unavailable when you first run the above code but thereafter the EnableSecurityDebugging setting in your project's user file will have been set to False and the code should run as normal.

首次运行上述代码时,您可能会看到有关 VS Hosting 进程不可用的警告消息,但此后项目用户文件中的 EnableSecurityDebugging 设置将设置为 False,代码应正常运行。

Thanks to Microsoft's ClickOnce team for their help on this workaround.

感谢 Microsoft 的 ClickOnce 团队在此解决方法上提供的帮助。

回答by javon27

I have yet another cause for why this message may come up. In my case, while testing cloning my solution from Git, I noticed that Visual Studio decided to set the Active solution platform to "Any CPU", whereas my startup project is explicitly targetting "x86". This caused the startup project to not build when I ran the build solution command.

对于为什么会出现此消息,我还有另一个原因。就我而言,在测试从 Git 克隆我的解决方案时,我注意到 Visual Studio 决定将活动解决方案平台设置为“任何 CPU”,而我的启动项目明确针对“x86”。这导致在我运行构建解决方案命令时无法构建启动项目。

Checking the Build box in the Configuration Manager for that project got rid of the error message.

检查该项目的配置管理器中的构建框消除了错误消息。

In case anyone asks, I don't remember exactly why that one project is explicitly targetting x86.

万一有人问,我不记得为什么那个项目明确针对 x86。

回答by Matus

For me the solution was to switch to "The application is available offline as well" in Publish tab of project properties

对我来说,解决方案是在项目属性的发布选项卡中切换到“应用程序也可离线使用”

Before I had "The application is available online only"

在我有“该应用程序仅可在线使用”之前

回答by Wazzy

A quick solution with no explanation on why: Running my application in "Debug" configuration stopped the error and allowed my application to run.

一个没有解释原因的快速解决方案:在“调试”配置中运行我的应用程序停止了错误并允许我的应用程序运行。