Tuesday, December 21, 2010

Debugging into NServiceBus so you can solve your own questions

Blog_Image In my previous post I talked about how one of the main problems with NServiceBus is the learning curve to become familiar with all the setup and configuration options. As NServiceBus is an Open Source project, you are able to to download the code. Once you’ve done this in a few simple steps you can start stepping into the source code as if it's your own code. Which makes solving some of the more complex questions with NServiceBus soooo much easier. For example, what does the "Lite" profile do? Well we can find out by stepping through the code. Here is a quick guide on setting up NServiceBus so you can debug into the code.

Downloading the Source code

The NServiceBus downloads page explains how to download the source code. I went for version 2.0 of the code.

You can get the source for the 2.0 release here.


Nservicebus_source_code_download

Compiling the source code to get at the pdb files.

Once you’ve downloaded the source code you’ll need to extract it:

NServiceBus_Extract_Source_code

  • Open up a command prompt and go to the extract folder
  • Type in build.bat





nservicebus_build

  • If it’s working it should immediately create a folder called “build” as in the following picture:

nservicebus_build_running_and_build_folder_001

  • It takes a while to complete. Once it’s done you should see “BUILD SUCCEEDED”

Nservicebus_build_success 

Setting up Visual Studio to support NServiceBus debugging

Once the build has finished, you can now reference the dlls and more importantly the pdb files which should be in:

NServiceBus-NServiceBus-280b6d9\build\output

To demo this we’ll create a new NServiceBus client using the Generic Host and the “Lite” profile.

  • Open up visual studio
  • File >> New >> Project
  • Select "Class Library"
  • Call it “NServiceBusDemo1”





nservicebus_vs_new_project

  • Click Ok
  • When your solution has loaded right click on the Solution in the Solution Explorer and click “Open Folder in Windows Explorer”
  • Create a new folder called “Dependencies”
  • Copy in the following 7 files:




  1. NServiceBus-NServiceBus-280b6d9\build\output\NServiceBus.dll
  2. NServiceBus-NServiceBus-280b6d9\build\output\NServiceBus.pdb
  3. NServiceBus-NServiceBus-280b6d9\build\output\NServiceBus.Core.dll
  4. NServiceBus-NServiceBus-280b6d9\build\output\NServiceBus.Core.pdb
  5. NServiceBus-NServiceBus-280b6d9\build\output\host\NServiceBus.Host.exe
  6. NServiceBus-NServiceBus-280b6d9\build\output\host\NServiceBus.Host.pdb
  7. NServiceBus-NServiceBus-280b6d9\build\tools\log4net.dll




from wikipedia:

“PDB stands for Program Database, a proprietary file format (developed by Microsoft) for storing debugging information about a program (or, commonly, program modules such as a DLL or EXE). PDB files commonly have a .pdb extension. A PDB file is typically created from source files during compilation. It stores a list of all symbols in a module with their addresses and possibly the name of the file and the line on which the symbol was declared. This symbol information is not stored in the module itself, because it takes up a lot of space.”

Which means that without the pdb files you won’t be able to step into the code and debug NServiceBus. The reason I like to recompile the source code is that the pdb files point to the directory containing the source code which makes life easier. Also it’s good practise anyway, so that if you want to change any of the source code you can.

  • This should result in a folder like this:

nservicebus_dependencies_folder

  • Go back to visual studio and add references to the dlls and exe

add_referencezs

  • Now we’ll create a very basic NServiceBus solution to demo the debugging:

Creating an NServiceBus “Client” to demo debugging

To demo this I copied the over the following 4 files from the FullDuplex example project into my new project:

  1. NServiceBus-NServiceBus-280b6d9\Samples\FullDuplex\MyClient\App.config
  2. NServiceBus-NServiceBus-280b6d9\Samples\FullDuplex\MyClient\ClientEndpoint.cs
  3. NServiceBus-NServiceBus-280b6d9\Samples\FullDuplex\MyClient\DataResponseMessageHandler.cs
  4. NServiceBus-NServiceBus-280b6d9\Samples\FullDuplex\MyClient\EndpointConfig.cs




myclientcopied

  • Go back to visual studio and include all the above files in the project

NService Bus Include Files

  • Next I’ll delete “Class1.cs”
  • If you try to compile at this point it will moan about the missing “message” project. So let's create that now:
  • Right Click on the solution in the solution explorer and click Add >> New Project
  • Call the new Project “NServiceBusDemo1_Messages”




NewProject

  • Copy over the following file into the “NServiceBusDemo1_Messages” project folder:
  1. NServiceBus-NServiceBus-280b6d9\Samples\FullDuplex\MyMessages\Messages.cs

Message_Class_copied_Over

  • Open up visual studio and include this file into the “NServiceBusDemo1_Messages” project :

Include MEssage class

  • Delete “Class1.cs”
  • Include Reference to NServiceBus




Include_Nservicebus_reference

  • We’ll need to reference the “NServiceBusDemo1_Messages” project from the “NServiceBusDemo1” project:

Include_Message_Project

  • Now we’ll need to update the app.config to reference the new project. Change the line:
<add Messages="MyMessages" Endpoint="MyServerInputQueue" />

to

<add Messages="NServiceBusDemo1_Messages" Endpoint="MyServerInputQueue" />

AppConfig_update

  • The solution should now build. Press F6 to test
  • Finally we’ll need to run the project using the generic host.
  • Right Click on the “NServiceBusDemo1” project and select properties
  • Click the Debug Tab
  • Select Start Action “Start external program:”
  • Browse to the bin/Debug folder of the “NServiceBusDemo1” project and select the generic host:




Running_Generic_Host

  • You should now be able to run the “NServiceBusDemo1” project in debug. To test put a break point on the Console.WriteLine( in the ClientEndpoint.cs file

Break_Point

  • Right Click on the “NServiceBusDemo1” project in the solution explorer and select Debug >> Start new instance
  • The program should break on the Console.WriteLine
  • Now press F10 until you get to the Bus.Send<RequestDataMessage>(m => line
  • Press F11 to step into the code




Stepped_into_code

  • That it. You’re now debugging the code and should be able to use this to help solve your own problems :)

17 comments:

  1. Thank you for your sharing of information. Here is the resource to solve the problem of api-ms-win-crt-runtime-l1-1-0.dll missing https://fix4dll.com/apimswincrtruntimel110_dll. If you will have it. Because I have been spent much time to fix that. No need to thank.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Nice & Informative Blog !
    Our team at QuickBooks Technical Support Phone Number 1-877-751-0742 makes sure to provide you with the best technical services for QuickBooks in less time.

    ReplyDelete
  4. Hey! What a wonderful blog. I loved your blog. QuickBooks is the best accounting software, however, it has lots of bugs like QuickBooks Error. To fix such issues, you can contact experts via QuickBooks technical support number

    ReplyDelete
  5. Avail the best offer and get the best fitness band under 2000 in india to achieve your fitness goal. Get the best device in India. best fitness band under 2000

    ReplyDelete
  6. If you're an singer apply for singing jobs in India, get freelance singers jobs, musicians jobs, rappers jobs, acting jobs, dancers jobs, choreographers jobs in India. jobs for actor

    ReplyDelete
  7. Unique gifts for all. Buy best gifts for your grandma, unique gifts for grandpa, gifts for sister, thoughtful gifts for dad and so on. thoughtful gifts for men

    ReplyDelete
  8. Hey! Nice Blog, I have been using QuickBooks for a long time. One day, I encountered QuickBooks Customer Service in my software, then I called QuickBooks Error 1328. They resolved my error in the least possible time.

    ReplyDelete
  9. Browse here for the best love, good morning, life, funny, sad, friendship quotes & status. Also get the best inspirational quotes etc. status in hindi

    ReplyDelete
  10. A really good article, very thankful and hopeful that you will write many more posts like this one.

    ReplyDelete
  11. Hey! Mind-blowing blog. Keep writing such beautiful blogs. In case you are struggling with issues on QuickBooks software, dial QuickBooks Customer Service Phone Number . The team, on the other end, will assist you with the best technical services.

    ReplyDelete
  12. Find the best best grill microwave, solo, convection under 5000, 10000, 15000 of best brand. best convection microwave oven in india

    ReplyDelete
  13. Hey! What a wonderful blog. I loved your blog. QuickBooks is the best accounting software, however, it has lots of bugs like QuickBooks Error. To fix such issues, you can contact experts via QuickBooks Phone Number

    ReplyDelete
  14. Looking for best fitness band to track heart rate monitor ? This is the place where you can get best fitness band in India. best fitness band india

    ReplyDelete