Debugging a library file

Let’s begin with a bit of background…

The company I currently work for has a bunch of Windows Form products build on .NET 4.5.
As the products are customised for each client that uses them, the product’s project architecture is loosely based on the following

> Core Framework
> Core Product 1
> Client 1
> Core Product 2
> Client 2

Each one of those is a executable product in it’s own right.
Each child is built on top of the parent product. E.g. Client 1 is built on Core Product 1, which uses Core Framework.

So, now on to the point of this post.

I was debugging some code in – let’s say it was Client 2 – and a particular method that came from Core Product 2 was executed. This method threw a NullPointerException, and I wasn’t able to drill down into the method as the current project only had a reference to it.
Now for reasons I won’t go into, I was not able to copy over the .pdb file for Core Product 2 without going through a few hoops.

Therefore, here was the easy (or lazy) approach I took as a work around

  1. Note the object and method that was being executed (for the purpose of this example, let’s call it User.UpdateName() ).
  2. Note the method parameters and their input values (taking note of null values).
  3. Open up the parent project (in this example, it would be the Core Product 2 project).
  4. Browse to the object and method that was to be executed by the child project (remember we’re looking for User.UpdateName().)
  5. Have a look in the code for any places you think a NullReferenceException could be raised, based on the parameters that the child project was intending to pass.
  6. And that’s basically it. Just scrutinize each line of code.

This worked for me, as I found that a condition was checking to see if an object’s int property had the value of zero (e.g. User.ID == 0), but was not checking to see if the object itself was valid. In my case, the object was null, hence the exception being thrown.

So, updating the check constraint to check for null or giving the object a default initialization prior to passing it could resolve the issue.

Hope that helps someone.

Subscribe

0 comments