We are migrating a gigantic solution to .NET Core. It builds and works in Windows and we can debug using Visual Studio without problems.
In macOS, however, we can run it, but still not build it due to some issues.
In the meantime I was trying to think of a way to debug code on Mac. Why doesn't this work?
Add this to one of my DLL files
// Start of my application
System.Diagnostics.Debugger.Launch()
// The rest of my application
Compile that DLL file and use it, alongside the PDB file, to generate my new application.
Navigate to that part of the code in Mac
Nothing happens. Unlike in Windows where that code allows me to attach a debugger.
How can I properly debug a part of my .NET Core code?
Yes, you can!
Install Visual Studio Code and then, instead of running "dotnet run" in the Terminal as always, you can start your API by pressing F5 (make sure you are not running in the terminal at the same time!)
Make sure you put a breakpoint in a place where you are going to use, and then hit an endpoint (for example, Postman).
I have installed the plugin "C#" from Microsoft, but I don't know if that helps...
Alternatively, you can try Visual Studio for Mac, but I found that this works in Visual Studio Code and I prefer it!
On Windows, you have an opportunity to hook up a debugger when the process hits a 'first chance exception'. The default debugger is specified in the registry, and you can find more information in - Configuring Automatic Debugging.
I don’t think that is possible in Mac OS X. Have a look at How does one automatically attach a debugger to a process at process start on OS X?
Also, I tried your code on macOS:
using System;
namespace DebugConsole
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Calling Debugger.Launch");
Console.ReadKey();
System.Diagnostics.Debugger.Launch();
Console.WriteLine("Continuing...");
Console.ReadKey();
Console.WriteLine("Hello, World!");
}
}
}
This builds successfully, but when System.Diagnostics.Debugger.Launch() is hit, on macOS the process does not hit the debugger. On a Windows machine it does. In short, this code should not be the reason why your code does not build on macOS.
Update:
Use Visual Studio Code to open your code. Visual Studio Code asks you to add file launch.json for the debugging configuration.
It will also download the .NET debugging extension which is required for obvious reasons.
You can launch your console application from here, but if you want to launch the process for some reason in the background and then hook up to it then you can do that as well. On the top you will see the menu next to the 'RUN' menu - this has two options. 'Dotnet core launch' will launch the process through Visual Studio Code and attach to it. 'Dotnet core attach' will attach to already running process.
If you select the 'attach' option, it asks you for the process to be attached. Refer to the screenshot below -
Please note that you will have to put a breakpoint in the IDE. As mentioned above, the debugger does not enter debug mode based on the Debugger.Launch() function call.
When running my solution in debug mode, IIS Express and Internet Explorer as the browser, I get the following error:
The program '[12604] iisexpress.exe: Program Trace' has exited with code 0 (0x0).
The program '[12604] iisexpress.exe' has exited with code 0 (0x0).
I'm using Visual Studio 2017. If I change to Chrome, I do not get this.
The only way to resolve this and still use IISExpress and IE is to go into my properties of the web project and uncheck Enable Edit and Continue under Debuggers.
Any idea as to why?
Try any of the following fixes....
Clean + Rebuild Solution
Restart Visual Studio
Run Visual Studio as Admin
Restart Computer
Launch Without Debugging
Ctrl + F5
Step Into Debugging
Hit F11 to start debugging by stepping into the first line of executed code. If that works, the problem is likely in your code somewhere (possibly an ehem StackOverflow Exception)
Break on CLR Exceptions
If there is a problem with the code on startup, you should break when thrown
Go to Debug > Windows > Exception Settings (Ctrl + Alt + D)
Select Common Language Runtime Exceptions
Change Project Port
Go to Project > Properties > Web > Project URL
Try using 8080, but any change might work
Create Virtual Directory
In the above screenshot, select Create Virtual Directory to the right of the Project Url
Delete .vs folder
Open the Directory where the solution / project lives.
Make sure hidden file are visible, and delete the .vs folder
Restart IIS Express
In the system tray, right click on IIS Express and select Exit
Enable 64 Bit IIS Express
If you're on a 64 bit machine...
Go to Tools > Options > Projects and Solutions > Web Projects
Select Use the 64 bit version of IIS Express...
Check Event Viewer
Check for any additional diagnostic information in Event Viewer under Windows Logs > Application
Run IIS Express from cmd line
You can rule out if there's an issue with Visual Studio or your Web Project itself.
Here's the docs on Running IIS Express from the Command Line
Pass in the path to the root of your project (where the web.config) is located
> "C:\Program Files (x86)\IIS Express\iisexpress.exe" /path:C:\repos\project\
Download IIS Express
Get the standalone installer for Internet Information Services (IIS) 10.0 Express and try again
Disable Edit and Continue
Go to Project > Properties > Web > Debuggers
Deselect Enable Edit and Continue although this will remove that functionality
Further Reading:
ASP.NET MVC5/IIS Express unable to debug - Code Not Running
IIS Express crashes when starting a site from visual studio
Unable to launch IIS Express Web server
I ran into this problem today. I had forgotten that I had set my application to a single instance application and I already was running another instance of the application in the background while I was trying to start another program instance.
To fix the problem you just have to open the program properties tab and uncheck the Make single instance application checkbox temporarily or close the same application running in the background.
My situation was too interesting. I tried all solutions of KyleMit but it didnt work.
So when i looked back to my previous commits in one of my service method i saw an action like this :
public List<Master> GetActiveMastersByCity(int cityId)
{
return GetActiveMastersByCity(cityId).Where(x => x.MasterStatus == MasterStatus.Active).ToList();
}
as you see there is a mistake in my method because in the scope the method name is wrong. it seems i tried call another method like GetAllActiveMastersByCity but i typed GetActiveMastersByCity is the same as my current method.
To be frank, this is too interesting adventure in my .net core story. Because its compiled and runned already and i did not understand absolutely why is this issue related with iis.
Hope it will helps you all.
I have been assigned to work on a Windows Service project. I installed it in my machine using installer class (ProjectInstaller.cs). I want to debug the source code and sometimes need to make changes while it is in debug mode. I attached the process via Debug menu to debug the project which works fine but it throw an error while I am trying to edit or continue the source code:
Managed Compatibility Mode does not support Edit and Continue
I googled and tried tons of solutions but none of them worked for me, couple of them are as below:
Unchecked the Use Managed Compatibility Mode from Tools -> Options
Unchecked Managed Compatibility Mode from Debug -> Attach to Process
-> Attached To -> Select...
Checked the Managed (v4.6, V4.5, V4.0) from Debug -> Attach to
Process -> Attached To -> Select...
Played with Platform target in Project Build.
Added {351668CC-8477-4fbf-BFE3-5F1006E4DB1F} field in my .csproj file
The error message varies depending on different solutions I implemented.
Below is the link I last time tried:
https://blogs.msdn.microsoft.com/visualstudioalm/2013/10/16/switching-to-managed-compatibility-mode-in-visual-studio-2013/
I am guessing: the last one didn't work because I do not have an exe project for my service instead I have implemented ProjectInstaller.cs Class and manually installed it through command prompt.
Any suggestion/recommendation are welcomed.
Edit and Continue requires many factors which are not obvious to users. Your case is simply not supported (mostly for attaching cases).
See Supported Code Changes (C#) in MSDN. In particular:
Edit and Continue is not available in the following debugging scenarios: [...]
Debugging an application that has Attach to instead of running the application by choosing Start from the Debug menu.
Unckeck Use Managed Compatibility Mode, It working for me! and you must Enable Edit and Continue in Debuging General
Attaching my process for each debug was a headache for me.
Just want to share a link that saved a lot of my time by writing a simple method and calling it in Main() method inside Program.cs.
This also gives me flexibility to edit and continue my code as simple as WinForm / Web Form. LOVE IT.
https://coding.abel.nu/2012/05/debugging-a-windows-service-project/
I reset the VISUAL STUDIO settings and the problem is resolved
hope it helps to Reset visual studio setting
I have started a new console project in VS2015. I only have this code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SautinSoft;
namespace PdfParser
{
class Program
{
static void Main(string[] args)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
SautinSoft.PdfFocus f = new PdfFocus();
f.OpenPdf(#"path:\abc.pdf");
if (f.PageCount > 0)
f.ToExcel(#"path:\abc.xls");
}
}
}
When I try to run, I get this :
Unable to start debugging. The startup project could not be launched.
Verify debug settings for the startup project.
How can I fix this? Thanks.
After upgrading MSVC2015 to Update3, I had the same problem: instead of std::map in the Watch window display as a horrible std::_Tree<std::_Tmap_traits... etc., some plugins started to throw exceptions, some projects was not able to run in debug mode.
All was solved by deleting CurrentSettings.vssettings. It is usually located at Documents\Visual Studio 2015\Settings If not, go to `Tools -> Options -> Environment -> Import and Export Settings ' to find the location of this file.
Had this on a brand new scaffolded ASP.NET Core 1.0 web application.
Solved with restart of Visual Studio.
I was also stuck with this. I removed both bin & obj folders, did a rebuild, and then it launched.
A very meaningless error....
I had this problem when I tried to start (without) Debugging my Asp.Net MVC project
are you running Visual studio as Administrator
so just restart visual studio As Administrator
Additionally to "Unable to start debugging"
I also had errors "The operation could not be completed: Unspecified error" when I tried to rebuild.
Thanks to Visual Studio popup: "the operation could not be completed"
it was enough to close Visual Studio 2015 and then open again.
Make sure you're launching Visual Studio as Administrator.
Right click on the Visual Studio 2015 Shortcut
Select the Shortcut tab
Click on Advanced
Check the box to "Run as administrator" at all times(see below)
This has resolved the issue for me with the exact error message in question.
It is not ideal to run the VS in administrator mode at all times. Make sure you un-check the box once your issue has been resolved.
There is no need to delete everything in my case, I just opened the
"CurrentSettings.vssettings"
file and commented this property
<PropertyValue name="DefaultBehaviorForStartupProjects">1</PropertyValue>
and everything fixed.
Sample
Just delete the .vs hidden folder. This folder resides at the same location where the sln file is. Deleting this folder also refreshes intellisense cache and would fix any issues with that. Hope this helps.
VS 2019, two Core 3.1 projects (an MVC and an API), brand new projects created, no other changes to the solution or projects.
I kept getting the referenced error when trying to start both projects within the IDE, despite having checked all the things already mentioned in this SO.
However, I finally realized, I forgot to specify the "Action" after switching the solution to "Multiple startup projects" (they were both still set to "None"). Right-click solution in "Solution Explorer", choose "Properties" (at very bottom).
Such a ridiculously simple thing. Hope it helps someone else.
"Broken"
Working
I just had the same problem and solved it by deleting the .vs directory in the project directory.
Delete all relevant /obj and /bin folders. Run again.
Close the Visual Studio and re-open it again.
Just restart your visual studio and run as admin.
I had this with a Xamarin.iOS project in my Xamarin.Forms solution. I tried every suggestion here, without success.
The source of the error was a misconfigured .csproj of the project. I never edited it myself and not even touched the project properties. I use Visual Studio 2017 RC.
I came across the solution when I compared the project file with previous versions on Source Control.
Solution: Compare the project file with a previous version and try to granually revert changes until you eliminated the problem and know what the cause was.
The solution for me was to delete all *.user files that are normally generated for both solution and project files
I found this problem too. But after restart the Visual Studio Community 2015 as an administrator I found new problem :
And then I try to open another solution, close the another solution, and open the solution which the problem occur, then the problem solved.
Had the Same Issue with the existing application, I deleted the vs settings but still the issue remained,
Finally i just restarted the VS and it worked fine.
I think sometimes when we load the project some library doesn't get loaded with the solution so the best option before doing anything is simply restarting the VS.
After adding a project reference 'MyProjectReference' to my app, then removing it, I was also getting the same error :
Unable to start debugging . The startup project could not be launched.
Verify debug settings for the startup project.
Deleting configuration, running as admin, restarting VS, rebooting machine all had no effect.
After running my web app without debugging (Right-Click Project -> View In Browser (Google Chrome) I got a much more useful error:
Could not load file or assembly 'MyProjectReference' or one of its
dependencies. An attempt was made to load a program with an incorrect
format.
My Solution was then to re-add back to the solution, then remove it again. After that rebuild and debug worked.
How I fixed my issue, I closed project that had that error , created new project build new project then opened the project that had an issue and build it. That worked for me.
Make sure you close all instances of Visual Studio and then restart as Administrator. In my case I had multiple instances of Visual Studio open and I had to close them all and then restart Visual Studio as admin in order to get things working.
I had visual studio 2015 with an ASP.net MVC5 arcitectured with DDD (Domain Driven Design). The problem was the same since I just opened visual studio normally.
The problem was solved when I closed all instance visual studio and restarted as an adminstrator.
I also faced to this issue in VS 2015 , but finally I resolved it by following bellow steps
In VS go to : Tools -> Options - > Projects and Solutions -> Build and Run
Select "Always Build" in "On Run when project are out of date"
This issue happened to me with the Latest VS2019.
I've tried everything here, but unfortunately without any result.
Finally, I've restarted the IIS server, also manually Recycled the "Default Application Pool".
After debugging issue fixed.
For me solution was to run testapp.csproj instead of testapp.sln. This can be selected from drop down next to green play button.
Simply updated visual studio which then prompted PC restart. This is what fixed the problem for me.
Note: I tried some of the above / below but to no avail.
I got this problem solved by clearing MEF component cache.
Use this VS Extension to clear cache very easily.!!
I stop debugging and exit the projects from IIS Express then clean and build the project and my error is gone.
I get this running as non-Adminsitrator in Visual Studio 2019 16.2.5, with two .NET Core projects.
The solution I found is to set at least one of the projects as "Start" (in Solution's Property Page). If both are set to "Start without Debugging" it fails. This happens even if I want to start the entire project without any debugging (Ctrl+F5).
Bug. Still unaddressed by Microsoft and their bug page issue report it is closed as unreproducible.
#Flowerking's commend did it for me.
Right click on you project and select "Set as StartUp Project".
I had this problem developing a react native app for windows in Visual Studio 2019. I started the debugger then stopped it in the terminal by using ctrl-C. I was not able to restart the debugger and the "start debugging" and "start without debugging" options were disabled in the debug dropdown. Restarting Visual Studio, etc, and some of the things described above did not work. Through hunting and testing, I noticed that if I switched views in the Solution Explorer to the MyProject.sln instead of the fileview, the debugging was enabled again. I'm not sure why, but it appears I need to be in the sln view to start the debugger.
Pls don't mark it as duplicate .. bcoz I have seen all the solutions but nothing is working for my case..
I have two machines devMachine and serverMachine
in devMachine I am developing application with Visual Studio and Now I have a simple Console Application..my need is I need to run this Console Application in serverMachine and debug from devMachine via Remote Debugging.
As told in Microsoft document, I have installed Remote Debugging tool in serverMachine and set the Authentication mode as Native (No Authentication) and run the Console Application in serverMachine.
Now , I have attached the remote process in devMachine's Visual Studio. All are working fine
But only problem is breakpoint is not hitting in Visual Studio
Note: I have placed required .pdb file in serverMachine and set that .pdb file path in devMachine's Visual Studio (Tools->Option->Debugging->Symbols).
Can anyone help me to resolve this issue?
What does the error message on the breakpoints say (if you hover over the breakpoint) - that it's different from the source? --> You can try disabling (from Tools/Options/Debugging) - Enable source file to exactly match the original version
What does the Modules window say - do the PDB's appear as loaded? if not, have you tried loading them manually (from the Modules window, right click the PDB and load)? - Is there an error message if it fails?
--> you might be in a case where the source files in the local machine are different from the ones on the remote one. Try copying everything over and see if that works (PDBs would be in the same folder as the EXE)
There are two reasons for the remote debugger to not hit the breakpoint
Wrong symbols.
Using the wrong .Net framework while debugging ( you can select on the "attach to process" window in visual studio).
Don't attach and just set remote debugging on. Copy all the project files to the identically placed and named folder in the server during post-build.
I had an issue with Visual Studio not breaking at my breakpoints although it looked like everything was setup correctly for the remote debugger on an IIS machine. I searched everywhere for an answer. The issue finally presented itself when I tried to manually attach the VS debug to a process (VS menu --> Debug --> Attach to process...) For some reason, there were multiple processes for the same application pool (there should only be one process, not sure where the others came from) I logged into my IIS server and killed all the processes for my application pool and then restarted the IIS application. When I saw there was only one process for the app pool (as I expected), I tried debugging in Visual Studio and it attached to the correct process. It turns out that when there were multiple processes for the same application pool, it attached to the "wrong" one.
Looking at your screen shot, could it be simply because the break points are in the "main" function which could already have finished before you can attach the debugger?
Suggestion:
Maybe put some artificial wait/delay code of say 20 secs in "main" above the first break point to give yourself enough time to attach to the process before "main" completes.