MonoDevelop debugger not attaching to WebAPI service - mono

I've got a Console application that is running an OWIN self hosted WebAPI service. When I run in in the Ubuntu command line every thing works fine however when I try and debug it in MonoDevelop, the main function just executes and then exits. I want it to remain debugging so I can make requests against the WebAPI but can seem to get it to not exit.
Is there something that I should be doing to make the debugger attach to the entire program?

How old is your MonoDevelop?
I just ran my MonoDevelop v5.11, and I can find the option "Attach to process" inside the "Run" menu. (This option was not present in prior versions, such as 4.0.x.)

Related

VS2022: how to make ASP.NET Core 5 app show it's console window

In VS2019, when I start my ASP.NET Core 5 app, which just exposes an API, if that matters, a console window pops up for that app. There used to be some setting to decide whether to run it as a console / standalone app or host it in IIS Express. I always preferred the console / standalone version because it lets me see the logs in realtime.
In VS2022, when I start the very same project, no window appears at all, and, interestingly, neither do I see IIS Express starting up.
How can I get back to having the project start as a console app? (Except starting it from the command-line and then attaching the debugger.)
UPDATE:
ok, so at long last I noticed that, strangely, a minimized console window is being created and because I start a dozen projects (microservices), I didn't notice before, and procexplorer telling me that the executable had no window added to the confusion. So this is much less problematic, albeit still weird - why does this one particular application not start un-minimized? The only difference it has to all the other executables is that it uses ASP.net core while the others (all background services communicating via messagequeue) don't.
and this only in VS2022, in VS2019 all executables including this one start unminimize
You have to make sure, that you selected "IIS Express" as your debug profile
VS 2022 debug profile
I believe you are looking for this. Follow the steps highlighted in in each image:
Go to your project properties:
Then you will see that the console is open in the task bar.
In Visual Studio 2022 this is currently NOT POSSIBLE

Attaching to process over SSH with VS2019 and ASP.NET core not working

I am running an asp.net docker container remotely. I have enabled SSH, mapped the port and also installed VSDBG in the container.
In visual studio I am able to attach to process over SSH. I choose my project dll file. There are no error alerts and it appears to be debugging but on every breakpoint there is this message:
The breakpoint will not currently be hit. The breakpoint is pending and will be resolved when debugging starts.
Also if I open modules window there is no entries.
What is going on? Why is remoe debugging not working?
There are usually two reasons:
1. project publication made with release instead of debug configuration
2. the projects are not consistent. There is a difference between the project on the local machine and the server.

.NET Core locking files

I have a ASP.NET Core app. I run the application by running the command
dotnet run
I'm seeing the following error in one out of five situations when I build this ASP.NET Core app.
C:...\error CS2012: Cannot open 'C:...\bin\Debug\netcoreapp1.0\AAA.Web.dll' for writing -- 'The process cannot access the file 'C:...\bin\Debug\netcoreapp1.0\AAA.Web.dll' because it is being used by another process.'
In addition to the above issue, I also see no updates that I make in the CSHTML file. I have to stop the dotnet run command, build the app again and then run the dotnet run command.
How can I fix these issues?
This may also help when running your aspnetcore app in IIS.
Add the following to your csproj:
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="echo "App Offline" /a > "$(ProjectDir)app_offline.htm"" />
</Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="del "$(ProjectDir)app_offline.htm"" />
</Target>
If it is on local and application is running on IIS, then in windows task bar before your date time, there should be a IIS Express Option. select IIS Express, select exit. Try running application again.
In my case, I got the same issue due to dotnet watch run command even after stopping the watch mode. Visual studio reported this error message :
The file is locked by: ".NET core Host (pid)"
killing the process with the pid fixed the issue.
When trying to kill the process using /taskkill /f /pid <number in the error> it was telling me the process didn't even exist.
I simply had to find .NET Core Host in Task Manager and end it there.
This occasionally occurs when I edit a test project on Core 3.0 - not using IIS, it's a class library and a test project in a solution only.
Open the Task Manager, find .NET Core Host, right-click, end task.
The dotnet watch command can track file system changes and edits and compile them in to the running process. This is done by first installing the Microsoft.DotNet.Watcher.Tools package in the tools section of the project.json file. See documentation of its usage here.
Once it is installed, you can then run the app with the command dotnet watch run and make edits while avoiding the manual restarting of the application.
I ended up recycling the Application Pool to get my dlls unlocked.
This has happened to me many times. The issue, at least in my case, has been that I have the application running. So when the compiler tries to update the dll it can't because the dll is locked and in use by the running application. Once I close the application and do the compile again, it works fine.
I may be a bit late to the party here, but for future people reading this question, it would appear that this is a bit of a 'feature' with how VS/core is able to interact with IIS and stop files from being locked:
https://developercommunity.visualstudio.com/content/problem/546858/bin-files-locked-by-iis-worker-process-1.html
It is apparently being investigated and looked into for .net core vnext.
I'm still running into this regularly in VS2017 and VS2019. Hopefully this helps someone.
This is what works every time for me.
If using IISExpress - Stop the Application using the icon in the task bar (near the clock/time)
If using IIS - Stop and Restart the site
OR
In an Admin command prompt run taskkill -F -IM node.exe (Kills all node processes currently running)
100% Working For Me
it is being used by another process .net core
go to task manager (for windows )
Right click .NET Core Host
click End Task
as like see this image
This problem offen when you set AspNetCoreHostingModel to "OutOfProcess"
then you have two solution for problem:
change hosting model to "InProcess"
use below command in CMD
taskkill /f /pid {.netcore hosting pid , show you in error line in visual studio}
For use that command, you do not use "" and {}.
For me, it worked by -
Go to your bin and the environment, take a backup for files, try deleting the folder
D:\CawProjects\EmailAnalytics\APIV1\APIV1\bin\Development
if it does not allow you to delete and says Open/Used somewhere then follow the below process.
Open task manager - find for .net core host and right-click to end the task

ASP.NET 5 - beta8: no rebuild in background

Before beta8 it was possible to start a Web Application, change some of the code (e. g. the ViewBag.Message of the About-View), save and refresh the browser - voilá, the new Message is displayed without rebuilding the project.
Now when creating a new Web Application with beta8 which uses DNX and Kestrel this seems no longer to work. Any idea why?
Beta8 contains a new library called 'dnx watch' which monitors your project files for changes during execution and automatically rebuilds the project. Install it by running the following from a command prompt:
dnu commands install Microsoft.Dnx.Watcher
Additionally, make sure you've installed the beta8 web tools for Visual Studio.
Finally, make sure you're not running in debug mode as code changes will not reload projects while running with the debugger attached. CTRL+F5 will start your web project without the debugger.
You can read up on this and the other changes in beta8 here:
http://blogs.msdn.com/b/webdev/archive/2015/10/15/announcing-availability-of-asp-net-5-beta8.aspx

Why is my module not in the modules list?

I have a WCF service that I can debug. I put a breakpoint in the code at the point at which I want to debug and get the message
The breakpoint will not currently be hit. The source code is different from the original version.
I have been struggling with this for 3 days now and have tried everything I have found in other posts.
One thing that I notice is that if I go to Debug -> Windows -> Modules the module that I want to debug is not in that list. I think this may have something to do with it. Does anyone know what I should do.
Thanks,
Sachin
EDIT:
I have tried all these things and many more, but for some reason I still have the same problem. Is there any solution to this at all?
Try closing down visual studio after closing any files open in it. Then go into your bin folder for debug and delete all .pdb files. Now reopen visual studio and rebuild your project or do a clean and build ensuring you are in debug mode and not release mode. This issue can arise if your pdb files become locked. If you have a pdb file present for that dll then it should pick up that module for debugging.
If that doesnt work have you restarted your machine? If not try a reboot as sometimes the process can get caught up in Windows, and restarting will release the lock to overwrite the files.
Quick question. Is the module in question an external module or is it part of your current solution that you are debugging? If it is an internal module then the solutions above should definetly work as you will generate a new .pdb file for that assembly.
To state the obvious, this error means that compiled service does not match the source code i.e. source code has changed since service run. Make sure you rebuild your solution.
What I do to debug WCF services is to have 2 instances of Visual Studio. One runs a WCF service hosting app (console) and the other runs a client. Make sure you are running debug version. It should work (and debug) fine as long as the client can successfully connect to your service.
You get
The breakpoint will not currently be hit.
when a module with that breakpoint has not been loaded (yet). Your service will not be loaded until a client connects.
Right click on the project inside the solution explorer and choose to Clean. Build a new version of the project and the breakpoint will work again. If this not work, try to delete everything from the bin and obj folders, and build again your project.