How to Test an IIS Module via Visual Studio? - c#

I'm working on an IIS module written in C#. I'm trying to test out some different types of functionality which is slowing down the development process. Right now I make the code change, build it, move the DLL to my web folder and refresh the website in my browser. This means I have to follow the stack trace every time an error occurs.
Is there some way I can run this directly from Visual Studio so if an error occurs VS will catch it and display the details allowing me to step back and forth through it?
Thanks in advance!

As long ad IIS loading modules DLLs you should be able to attach Visual Studio debugger to the IIS working process, try out to attach to the w3wp.exe process

Related

debugging asp.net web service remotely

I'm trying to attach to a Web service remotely from Visual Studio (2008). I can attach to processes on the remote machine, but when I attach to w3wp.exe, the breakpoints in my code say "The breakpoint will not currently be hit. No symbols have been loaded for this document".
Something I noticed is that after attaching, the DLL of the service doesn't appear in the list of loaded modules, but I can see other DLLs referenced in the project...
Am I attaching to the wrong process? Only one w3wp.exe instance runs on the remote machine...
UPDATE
Apparently, the remote debugger needs to be installed to allow stepping into web services, it cannot be done if the remote debugger is running from a share.
Since I couldn't make it work and I don't have access to the VS 2008 installer to properly install the debugger on the remote machine, I decided to upgrade the project to VS 2010 (of which I do have the installer)...
However, I still have to manually start the debugger and add permissions to be able to attach... Is there any way you can set additional permissions when the debugger runs as a service?
If the debug symbol resources (*.pdb) are not right there with the libraries then I would say that your solution wasn't built for Debug but rather for Release (or some other build target).
I've personally not been able to attach the debugger to a project without those symbols being loadable. As a solution I'd recommend rebuilding the project for Debug and then deploying it to the suspect environment that needs your debugger.

Remote Debugging Error

I've been refactoring some code which was previously working.
Now when debugging I get to a break point in the refactored code and when I step into the Property in question I get a message saying that Windows firewall is currently blocking remote debugging.
It doesn't make sense because the application is a console application being debugged through visual studio on my local machine. I am using VS2010 and .net 4.0.
Does anyone know why vs might be trying to remote debug?
what does your code do? does it access any external files and or databases?
It could also be an administratrion issue, try rightclicking VS and run as admin first off and see if that fixes the issue.
secondly trace your code and see if there is any links to externals, and thirdly go to windows firewall and change the settings to allow access to Visual studios~ and or databases/.net instances.

remote debugging asp.net

I have a server running my web app through IIS. I have visual studio locally, I am attaching to the remote w3wp.exe process with no issues, but my breakpoints are not being hit because my symbols are not loaded.
What am i missing?
Update: Should I be debugging Native or Managed? When I do Native, the Modules window shows a ton of windows dll's that all fail to open the PDB. Should I be concerned? I do not see my dll in the list. When I use Managed, the modules window is completely empty.
Found the issue. When I was attaching to the process via the Visual Studio gui, the w3wp.exe process was listed as x86 instead of Managed 4.0. I recreated my app's site in IIS and the process went back to being listed as Managed, which allowed the symbols to be loaded.
Make sure that you built your project in debug mode. Also, make sure you have sufficient rights for your remote server.

Debug application running outside Visual Studio

I develop C# applications using VS 2010 Ultimate.
Usually, those applications run for long time, without user interaction and, of course, they usually have bugs inside.
Unfortunately, often the application crashes randomly and you just can't reproduce the error. Also sometimes I only have the message "The application has stopped working" with no more informations.
I can install Visual Studio on the machine of the customer, but I can't let him run VS and compile/start the source code in debug mode! What I need is to start VS after the application was started and crashed. It seems to be possible to do this, in fact when an exception happens at runtime, Windows ask you "do you want to debug with VS?", but if I answer YES, then VS starts but simply I can't see the source code (it is on the pc as well), thus I can't inspect the row of code that is causing the exception. VS just tells me "source code not available". Actually, I can't imagine how Windows could start VS and know where the source code of the crashed application is!
Does anyone knows how does this debugging scenario is intended to work, and how to configure it??
Thanks a lot,
Simone
Windbg debugging tool solves the purpose.
Take dump of the process state and start analyzing with windbg. It gives you the exception information
To debug from an already-running Visual Studio instance, select the "Debug" menu item, then "Attach to Process..."
Next, select the executable from the list, press "Attach" (or double-click), and you are now debugging the application. When you select "Yes" and Windows says that source code is not available, this most likely means that the PDB wasn't able to be loaded, so make sure that you have loaded the symbols for the module by examining it in the "Modules" window pane.
If you want to catch errors while running compiled program, you should use some sort of logging mechanism. These days you don't have to write it on your own, there's a great opensource logging engine designed for .NET applications, it's called NLog. It's capable of saving logs into files, emails, console or database, pretty much all you can want :).
Hope this helps :)

ASP.NET failing to call an unmanaged dll after initial request

So I have an unmanaged C++ dll which I am calling from my ASP.NET application, it has a single entry point and a couple of structures for passing data. If I create a C# console app to call the dll it works fine. If I hook it in to my asp.net app running on my local WinXP machine (IIS 5.1) then it works fine.
When I publish it to our development environement which is running Windows 2003 and IIS 6 then the first 1 or 2 calls works fine but then it simply stops responding. I'm getting no error messages, warnings etc... but I am fast running out of hair!
I've set the virtual directory which runs the asp.net app up inside of its own application pool but this seems to have had no impact. Any help would be greatly appreciated.
Cheers
What do you mean when you say that it stops responding? You could try putting logging statements that would trace the input/output around the call to see where exactly it blocks. Also make sure you check the server Event Log where unhandled ASP.NET errors are written. As a last resort you could install Visual Studio remote debugging tools (msvsmon.exe) on the server and step through the code by attaching to the corresponding w3wp process. Actually the debugging tools doesn't require installation, a simple copy is enough (C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Remote Debugger).
The failure appears actually to be with the C++ code itself, it has some code to handle locking for a threaded environment and this appears to be failing. Not sure why it works on my local machine and not the dev environment but that's another question.
Thanks all

Categories