64

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

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

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

enter image description here

And then, nothing happens. Nothing starts.

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

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

stuartd
  • 70,509
  • 14
  • 132
  • 163
Hathors
  • 693
  • 1
  • 7
  • 13

11 Answers11

41

This solved my issue:

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.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
ATD
  • 824
  • 1
  • 9
  • 14
20

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.

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

Jonathan Alfaro
  • 4,013
  • 3
  • 29
  • 32
Scott O.
  • 898
  • 1
  • 9
  • 15
  • I have a ClickOnce WinForms app that depends on 2 services, also in the solution. Moving the WinForms above the two others at startup did the trick! Thanks. – Przemek Sep 28 '17 at 11:02
  • OMG I can't believe this worked! It makes no sense, but works perfectly nevertheless. – MEMark Jan 02 '18 at 18:30
  • after successful running I moved back the client at the end again to start, it also works now. Closing and reopening VS might do the trick may be :) – SArifin Mar 13 '18 at 23:27
  • 1
    I had to switch the load order to make it work. Restarting VS definitely didn't do anything. Switching the load order allowed VS to modify the WPF file properly, since the service wasn't debugging already. After allowing it to do that, you can switch the load order back without any issues. You just have to make sure that it is able to modify the project file before it gets into debugging the service. – Grungondola Jun 08 '18 at 14:45
15

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

Go to Projct > Properties... > Build

Uncheck the checkbox Prefer 32-bit

enter image description here

Morris S
  • 2,337
  • 25
  • 30
  • 1
    I also noticed that `optimize code` was true for debug mode. For me, turning`optimize code` off did the trick! Thanks for the post. – Kabua Jan 11 '19 at 15:44
  • 1
    Mate, you just saved me and a lot of other people hours of work. Thank you. – Sachin Kainth Jul 22 '19 at 15:08
5

MS have removed the VS hosting process in VS2017 - see

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.

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.

jon morgan
  • 149
  • 1
  • 6
4

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:

  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

Properties

Mats
  • 41
  • 2
1

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.

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:

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

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

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

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

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

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.

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

jon morgan
  • 149
  • 1
  • 6
1

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.

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.

javon27
  • 316
  • 2
  • 10
1

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.

0

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"

Matus
  • 410
  • 5
  • 15
0

My issue seemed to be associated with the folder that the solution was in. My DEV branch solution worked without issue but the CERT branch (different local folder) gave the Security Debugging message when the ClickOnce Security settings were checked.

My solution: launch VS2019 as Admin. Problem is gone when debugging. And now I can launch without Admin and debugging is still good.

wagtod
  • 1
  • 1
-1

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

Wazzy
  • 1
  • 6