question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running the console app

See original GitHub issue

Problem encountered on https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/run Operating System: windows

using Powershell ISE in Admin mode, I get this:

> PS F:\net6\myapp> dotnet run
dotnet : System.ComponentModel.Win32Exception (5): Access is denied.
At line:1 char:1
+ dotnet run
+ ~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (System.Componen...cess is denied. 
   :String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    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)

Using the default command line in admin mode, I get this:

F:\>cd net6\myapp

F:\net6\myApp>dotnet run
System.ComponentModel.Win32Exception (5): 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)

F:\net6\myApp>

BUT, Using VS 2019 (Version 16.9.4), after opening the .csproj file, and running the project, I get this:

Hello World!

F:\net6\myApp\bin\Debug\net6.0\myApp.exe (process 17640) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

The web instructions state that I should get the result that came with using VS 2019, from the regular commandline, run in the project directory, but this fails. Is this known Issue? If yes, is there a workaround that does not involve the IDE?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dsplaistedcommented, Aug 9, 2021

It sounds like dotnet run isn’t working from admin command prompts for you. I’m not sure why that is happening. So I asked you to try running the app without dotnet run in order to try to narrow down the issue.

dotnet run from the project folder should work, but I don’t believe dotnet run myApp.dll or dotnet run myApp.exe has ever worked.

@joeloff Any ideas here?

1reaction
cobaltsoftwarecommented, May 19, 2021

Following the suggestion, here’s the Build Result: PS F:\net6\myApp> dotnet build Microsoft ® Build Engine version 16.10.0-preview-21181-07+073022eb4 for .NET Copyright © Microsoft Corporation. All rights reserved.

Determining projects to restore… All projects are up-to-date for restore. You are using a preview version of .NET. See: https://aka.ms/dotnet-core-previ ew myApp -> F:\net6\myApp\bin\Debug\net6.0\myApp.dll

Build succeeded. 0 Warning(s) 0 Error(s)

Time Elapsed 00:00:01.68

I then tried to run the exe from outside of the \bin\Debug location: `PS F:\net6\myApp> cd bin\debug

PS F:\net6\myApp\bin\debug> dotnet run .\net6.0\myApp.exe`

and got this as the Result: dotnet : Couldn’t find a project to run. Ensure a project exists in F:\net6\myApp\bin\debug, or pass the path to the project using --project. At line:1 char:1

  • dotnet run .\net6.0\myApp.exe
  •   + CategoryInfo          : NotSpecified: (Couldn't find a...sing --project. 
     :String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    

Next I went to the fq location, and made sure that I was in the right place: PS F:\net6\myApp\bin\debug> cd net6.0

PS F:\net6\myApp\bin\debug\net6.0> ls

Directory: F:\net6\myApp\bin\debug\net6.0

Mode LastWriteTime Length Name


d----- 5/9/2021 11:52 AM ref
-a---- 5/12/2021 2:57 PM 164864 myApp.exe
-a---- 5/12/2021 2:57 PM 407 myApp.deps.json
-a---- 5/12/2021 2:57 PM 165 myApp.runtimeconfig.json
-a---- 5/12/2021 2:57 PM 379 myApp.runtimeconfig.dev.json -a---- 5/12/2021 2:57 PM 4608 myApp.dll
-a---- 5/12/2021 2:57 PM 9620 myApp.pdb

Upon seeing that I was in the right location to comply with the suggestion, I ran this: PS F:\net6\myApp\bin\debug\net6.0> dotnet run myApp.exe

And got this as a result: dotnet : Couldn’t find a project to run. Ensure a project exists in F:\net6\myApp\bin\debug\net6.0, or pass the path to the project using –project. At line:1 char:1

  • dotnet run myApp.exe
  •   + CategoryInfo          : NotSpecified: (Couldn't find a...sing --project. 
     :String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    
    

Obviously this was done in PowerShell, but that is how my machine is set up.

Thoughts? Suggestions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a .NET console application using Visual Studio
Run the app ... Press Ctrl + F5 to run the program without debugging. A console window opens with the text "Hello, World!"...
Read more >
How to run .NET Core console application from the ...
Open a command prompt or terminal window. · Navigate to the directory that contains the compiled executable file of your .NET Core console...
Read more >
4.8 Running Stand-alone Console Apps - Learning C#
In this video, I explain what happens in the background when we run a console application in Visual Studio, and how to compile...
Read more >
Run and Debug Console Application - YouTube
This screencast helps you get started with running and debugging a simple .NET console application with Project Rider.
Read more >
Running Console Applications from Windows
Console applications were often originally written to run under DOS but will run equally well from a Windows console application window.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found