Mark Oliver's World

Posted: 05/03/2024

Using ObjectDumper Breathed New Life Into A Complex System

For a previous article on Testing in Dotnet, I wrote about the package ObjectDumper.Net

I use this for lots of things, but it is great to add to a test to really see what an object looks like.

So it was obvious for me that I needed to write more about that!

But when I started writing this article (last summer), ChatGPT was everywhere (not that this has changed), so i thought, lets see what it can tell me about ObjectDumper.Net as a start to the article.

Overview From ChatGPT

Prompt: Tell me why we should use ObjectDumper.Net

ChatGPTs response was:

ObjectDumper.Net is a useful tool for developers working with .NET applications, especially during debugging and data exploration processes. Here are some reasons why you might consider using ObjectDumper.Net:

  1. Easy Object Visualization: ObjectDumper.Net allows you to visualize the contents of an object in a human-readable format. It can recursively traverse object graphs and present the properties and values of each object in a structured manner. This makes it easier to understand complex object hierarchies and quickly identify the data you're interested in.
  2. Debugging Aid: When debugging an application, it's often necessary to inspect the state of various objects at runtime. ObjectDumper.Net simplifies this process by providing a convenient way to dump object data to the console or a text file. You can quickly examine the properties and values of objects without having to write custom code to traverse and display them.
  3. Rapid Prototyping: During the early stages of development, when you're experimenting with different code structures and data models, ObjectDumper.Net can be a handy tool. It allows you to visualize objects and their relationships, making it easier to validate your assumptions and verify that your code is behaving as expected.
  4. Exploration and Documentation: When working with unfamiliar libraries or APIs, ObjectDumper.Net can assist in exploring the available objects and their properties. By dumping objects to the console or a file, you can study their structure and understand the data they hold. This knowledge can then be used to document the behavior of third-party components or to aid in writing code that interacts with those objects correctly.
  5. Customization and Extension: ObjectDumper.Net provides various customization options to tailor the output to your specific needs. You can control the depth of object traversal, exclude specific properties, or define custom formatting for property values. This flexibility allows you to adapt ObjectDumper.Net to your preferred output style or integrate it seamlessly into your existing debugging workflows.
  6. Open Source and Community Support: ObjectDumper.Net is an open-source project, which means it benefits from community contributions and support. If you encounter any issues or have suggestions for improvements, you can engage with the community, report bugs, or even contribute your own enhancements to the project.

Overall, ObjectDumper.Net is a valuable tool for .NET developers that simplifies the process of visualizing and exploring object data. Whether you're debugging, prototyping, or documenting your code, ObjectDumper.Net can save you time and effort by providing an easy-to-use mechanism for examining the contents of objects in a human-readable format.

I was very happy with the response. I found it helpful, and it covered everything I would have said about it.

So let me tell you a bit about how ObjectDumper.Net has helped me to view the internals of a complex application.

Usage Example

I have inherited a software system that integrates with a very complex third party system. It is used to record calls that are happening on a Phone Exchange (PBX).

This system is very complex and must maintain a lot of state when receiving data from the third party application. It requires that state to follow a phone call through the changes within the PBX, and allows the recording software to show useful meta data about the call. e.g.

  • Who made the call
  • Who received the call
  • What call queue it went through
  • How long was the call
  • What other participants were involved in the call
  • Were any keypad buttons pressed during the call
  • etc...

Think of it like this: The call recording software is primarily used in call centres...

"This call is being recorded for safety and for training purposes"

... so thousands of calls go through a PBX in a day. They come in. They go out. They get transferred between departments, people & groups of people. They get put on hold. They get sent to voicemail etc...

All of these changes need to be retained to allow the recording to be identified for those "training purposes".

It should be clear now, that the journey of a call can be very complex!

Debugging this system that had no documentation on how it worked, nothing on how it was architected/designed and no automated tests was incredibly hard!

Quickly in using and debugging the system, it became clear that the state of the "recording" was the most important part.

This state data was dynamic, and had to morph for different recording PBX types.

The complexity and fragility of this system and the fact that it was used in 100s of production environments meant that we needed to tread lightly in the code for fear of breaking things.

We needed a way to log out the contents of the state as it changed, which would allow analysis of a calls journey through the system and its state changes with a few small code changes.

What we needed was to output the state without knowing what it was made of!

In enters ObjectDumper.Net!

If we add a small log message that has the state "dumped" out, we could add a huge amount of context to what was going on:

            Logger.Debug($"State of the call at {timestamp}: {call.State.Dump())})
            
          

This was a game changer for this system, and the overhead of the "Dump" was minimal for the benefits it gave us (although we could compile it out if we wanted to).

I highly recommend ObjectDumper.Net as a quick way to view the contents of an object without retrospectively adding ToString() method everywhere (though I highly recommend them too!)

I wrote more about why this was useful for tests in this post Querying Console Output In Your Tests.

I will leave you with a final comment - ObjectDumper.Net will write out the whole contents of an object, and it can be full of unhelpful data, so use it wisely.

Look at the output it is giving, and ideally replace it with more structured logs if you can!


Thanks for reading this post.

If you want to reach out, catch me on Twitter!

I am always open to mentoring people, so get in touch.