Search code examples
c#asp.net-core.net-corevisual-studio-2022

Unable to start program, Access is denied C# net6.0


I have this issue where some of the projects I created for.Net6 throws the error shown in the image attached

enter image description here

In this instance the project was running fine, suddenly, the error started to pop up. I have tried to find a solution by myself and on the internet.

I have used different IDEs VS 2022, ReSharper, VS Code, and the error persists.

This started when I installed VS 2022 and .Net6 SDK. Was formally using VS 2019.

Any help?

So, what I have done so far was to do a system reset. Everything was working well until a couple of hours now. I tried to use CMD as admin to run. I would like to point out that I have a couple of projects on the solution, but one keeps throwing this error.

System.ComponentModel.Win32Exception (5): An error occurred trying to start process 'C:\Users\xxxxxxxxxxxxx\source\repos\ProjectTemplate2022v3\src\Skoruba.Duende.IdentityServer.Admin\bin\Debug\net6.0\Skoruba.Duende.IdentityServer.Admin.exe' with working directory 'C:\Users\xxxxxxxxxxxxx\source\repos\ProjectTemplate2022v3\src\Skoruba.Duende.IdentityServer.Admin'. Access is denied.
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Microsoft.DotNet.Cli.Utils.Command.Execute(Action`1 processStarted)
   at Microsoft.DotNet.Cli.Utils.Command.Execute()
   at Microsoft.DotNet.Tools.Run.RunCommand.Execute()
   at Microsoft.DotNet.Tools.Run.RunCommand.Run(String[] args)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)

Solution

  • I had the same problem and later figured out that Windows Security (Defender) was blocking the executable.

    Go to Windows Security -> Virus and Threat protection settings -> Exclusions and add your exe to the exclusion list.