Debugging ASP.Net applications with SharpDevelop

September 25, 2009

Warning! Long post ahead, go straight to bottom if you want to debug ASP.Net applications with #D

How I started programming ASP.Net

Recently i’ve changed jobs and thus I changed my profile from .Net dekstop apps to ASP.Net web site programming. (Yes, from now on there will be more Internet ;)) Along with new job, I got also new tools:

  • VisualStudio + Resharper
  • Microsoft SQL Server Management studio
  • Team Foundation Server for source control
  • ASP.Net Web site development

Coming from a completely different environment, where, for the past 4 years, i worked with SharpDevelop, Windows forms, Boo, OpenOffice, FlameRobin + FireBird, Svn, nant, I must say that for a few weeks and still now I am feeling like a baby born in a completely new world.

My experience so far has been not that much exciting, though. Here are the reasons:

VisualStudio + Resharper

Good points:

* Resharper gives more refactoring options.  The ones I used already: convert property to automatic property, use a base parameter in a method instead of concrete implementation, introduce field, extract method.

*Automatic error checking is a nice feature.

And finally i got a change to work with .Net 3.5 !  (of course it has nothing to do with #D or VS)

Quirks and nuisances:

  • Ccode formatting is tragic.

It formats not only the indentation, but also line brakes, which is very annoying. Imagine i want to make a few spaces in aspx file after a div element. Nope, visual studio will remove those spaces. When i went to options and tried to tell VS to not mess around with line breaks, formatting tools stopped working at all complaining about bad configuration.

  • It is sooo damn slow!!!!

I do not know why, but even to save a file it took around two seconds. To build a already up-to-date project took around 20 seconds, while on #D it takes only 5 seconds!

To even start-up visual studio takes a minute. Compare this to #D 10 seconds, where in 4 seconds #D is ready to run and you can start typing. Parsing is finished in the last 6 seconds, which is very fast compared to VS.

  • It does not have a decent a decent “go to” function, which is #D.

I found though go to file and go to type, but when i type a file name, the search is made only for the end of file, not for begining and end of file. That is, if you have a file named “myCompany” and you type “company” both tools will show you nothing.

Lastly, in #D you can enter digits and those will be understood as line numbers, while on VisualStudio you have to use a “go to line number” function. Why three functions instead of one!? It jus makes no sense.

  • “Go to declaration” strange behaviour

Go to declaration in visual studio and go to parent class are two different functions in VisualStudio. If i press ctrl-enter on a variable of type MyClass in #D, it will go to the place where that variable was declared. If i press again ctrl-enter on a type of my variable, it will take me to the implementation of the type MyClass. Nice and painless, but not in VS, where these two functions are separate.

  • VS does not allow to edit source code, while compilation is in progress. Or at least, it complains that everything will go very bad if i do so

I am not sure why VS complains about it, but it appears that #D is doing that with no problems.  Of course i know that if i change a code during the compilation, and i will save it, compiler might report errors if i edit code in incorrect way. Afterall, i am a programmer, so i know the implications of what i am doing.

Microsoft SQL Server Management studio 2008

  • Microsoft SQL server management studio lacks intelissence, which is very suprising.

With FlameRobin you have intellisense for SQL keywords, for tables, for table columns.  With Flamerobin you can copy results “as insert statements” or “as update statements”. This helps a lot and saves a lot of typing.

  • AFAIK, by default all scripts are executed without trasactions

So if you play with your queries, it is your own responsibility to not mess everything up. Of course, if you run a script a few pages long, half of it executes, and half of it not.

Team Foundation Server for source control

TFS source control is a very very strange piece of software indeed. Imagine this: when you checkout all source from the server, all files are initialy with ReadOnly attribute. Yes, that’s right, that is how TFS distinguishes which files have modifications, and which do not. Now, if you remove the attribute and try to edit the file with another editor, TFS will not understand what is happening. The reason is that when you edit a file from VS, TFS checkouts the file for editing, that is, removes the readonly attribute and contacts TFS server to mark that file as being edited. Furthermore, AFAIK this scheme does not allow for two people to edit the same file at the same time.

Check in dialog is also somewhat not useful: it does not remember previous checking message. Merge is done also in an interesting way. Instead of merging automatically, it asks whether the user wants to automatically or manually merge the file. I know of situations when i would like to manually merge files (for example css files, csproj files, and sln files), but for any other files i would like automatic merging to occur immediatelly! Why bother me with even more clicks.

I could not find a “blame” command in TFS.

When compiling the project, the compiler, as we all know, produces files into obj\ and bin\ directories. However, when this is happening, TFS is checking if those items are inside TFS server and every times reports that no files in the server where found. This happens even when obj and bin folders are set to be ignored.

ASP.Net Web site development

Web site development deserves also it’s own point. Note that there there is ASP.Net website and ASP.Net application. The difference in the two is that with web site there is no csproj files, and if you want to compile your site, the compiler does not know which files to compile! So what it does then? The compiler then goes recursively into each directory and builds each directory separately. Image that this operation is very slow. It is so slow, that completely rebuilding a website took around 5 minutes, of which 4 minutes probably went to website compilation.

References are managed also very interestingly. When you click “Add reference” in ASP.Net website and choose an assembly, a file named <YourAssemblyName>.refresh is created in the bin directory. Yes, that means that this .refresh file has to be inside your source control! And that means that part of the bin folder must be in your repository. Now what is inside that .refresh file?  Simply a relative path to the original library file! For example, in a file “YourApp.WebSite\Bin\log4net.dll.refresh” file you would find this text: “..\Libraries\Log4Net\log4net.dll”

How to debug ASP.Net applications with SharpDevelop

Luckily, the situation changed quite soon. The following happened:

  • TFS was switched to SVN. Hurray!
  • WebSite was changed to WebApplication.
  • Having this changes, i could successfully load our web application solution with SharpDevelop 3.x and compile it.

Of course, #D does not support debugging web applications out of the box. I tried to attach to w3wp.exe process (a process associated with application pool in ISS), but sadly my system is WindowsXP 64, so w3wp.exe process is a native x64 app, and thus it does not allow to attach to it. Debugging x64 applications is not yet supported in #D. But there is a solution to use your own native web server, and there is such – a Cassini web server.  You can find it here in dmitryr’s blog.

Here are the steps to set everything up

  • Compile Cassini server for x86 architecture, so that #D could debug it.  #D does not yet support debugging x64 native applications
  • In your web applications csproj file in Debug tab set the following arguments
  • Start external program must point to your Cassini web server
  • First argument is path to your web application directory
  • second argument is the port
  • Third argument virtual path, such as ‘/’

Now you should set a break point and point your browser to your app, the breakpoint should be hit.

You can even execute cassini as a stand-alone application, or even as a windows service, and attach sharp develop to that process.


2 Responses to “Debugging ASP.Net applications with SharpDevelop”

  1. Adomas said

    Thanks, I had a good read! (And lot of memories, not all of which are great as you could imagine). I’m thinking of having a look at 2010 Betas sometime soon, but you just gave me a cold shower. Which version of VS were you *trying* to use?

    • dariusdamalakas said

      At the moment VS2008.
      A coworker has had already a look at 2010, and says nothing changed to the better. I still have to use VS2008 time to time, since SharpDevelop does not generate code behind files for aspx pages.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: