Skip to main content

WP7Contrib: Getting debug information from the NuGet packages

When using the WP7Contrib packages from you will be using the release build versions of the assemblies. Unfortunately what you won't get is the debug information generated by the services and other classes in the contrib. What is detailed below is steps you can use to get this debug information when using the packages.

I am aware NuGet now supports the publication of PDBs & symbols to (more info can be found here). We haven't yet got round to factoring this into our publication process. When I say process, I mean when I use NuGet Package Explorer to do the publish to NuGet. I'm not sure the explorer currently supports this feature (hopefully I'm wrong). When this is done you'll be able to step through the contrib code base.

We also provide another way to get debug information at runtime via the ILog interface. The caching, communications & services namespaces make use of this interface. Like all dependencies in the contrib it can be injected in via the class constructor - all these classes provide overload constructors for this.

So the interface looks like this:

public interface ILog
    ILog Write(string message);

    ILog Write(string message, params object[] args);

    ILog Write(string message, Exception exception);

    ILog WriteDiagnostics();

Before I show how I implement a local version of this to help debug an application, lets see how an example application using the Bing Maps Wrapper service (out of the box) doesn't produce any logging information.

So the following code makes a call out to Bings Maps API to get the location information for a post code (zip code). As you can see from the highlighted box the only output is the write line from the Rx subscriber when the result is returned.

Now this is great when the code has executed the 'happy path', but what happens if something goes wrong because of bad input data or there is a bug in the contrib? You're not going to see anything helpful coming out of the contrib apart from maybe a formatted exception.

This is where the ILog interface comes into play, if you have an implementation that uses the Debug.WriteLine() method you can quickly see what is going on under the covers.

Shown below is a class I drop into any solution using the NuGet versions of the contrib, you can get a copy here  (DebugLog.cs):

public sealed class DebugLog : ILog
    private const string DateFormat = "dd-MM-yyyy HH:mm:ss.fff";

    public ILog Write(string message)
        Debug.WriteLine(string.Format("{0} - {1}", DateTime.Now.ToString(DateFormat), message));

        return this;

    public ILog Write(string message, params object[] args)
        var messageWithParameters = string.Format(message, args);
        Debug.WriteLine(string.Format("{0} - {1}", DateTime.Now.ToString(DateFormat), messageWithParameters));

        return this;

    public ILog Write(string message, Exception exception)
        var date = DateTime.Now.ToString(DateFormat);

        Debug.WriteLine(string.Format("{0} - {1}", date, message));
        Debug.WriteLine((string.Format("{0} - Exception '{1}'", date, exception)));

        return this;

    public ILog WriteDiagnostics()
        return this;

You then have to wire this into the contrib classes that accept an instance of the ILog interface. Shown below is the re-worked example from above.

As you can see you get a lot of information in real-time about what's going on inside the contrib. In this case you can see the call out to the URL endpoint, the response headers returned, the deserialization time for the returned data and finally the result being added to the In Memory Cache Provider.

I hope this helps someone trying to use the contrib :).

Also, we don't currently use any AOP tools to weave in debug\trace information but this might well be added in the future, and we are going to improve our constructors for classes - to make these easier to use for people not working with DI frameworks.


Popular posts from this blog

Showing a message box from a ViewModel in MVVM

I was doing a code review with a client last week for a WPF app using MVVM and they asked ' How can I show a message from the ViewModel? '. What follows is how I would (and have) solved the problem in the past. When I hear the words ' show a message... ' I instantly think you mean show a transient modal message box that requires the user input before continuing ' with something else ' - once the user has interacted with the message box it will disappear. The following solution only applies to this scenario. The first solution is the easiest but is very wrong from a separation perspective. It violates the ideas behind the Model-View-Controller pattern because it places View concerns inside the ViewModel - the ViewModel now knows about the type of the View and specifically it knows how to show a message box window: The second approach addresses this concern by introducing the idea of messaging\events between the ViewModel and the View. In the example below

Implementing a busy indicator using a visual overlay in MVVM

This is a technique we use at work to lock the UI whilst some long running process is happening - preventing the user clicking on stuff whilst it's retrieving or rendering data. Now we could have done this by launching a child dialog window but that feels rather out of date and clumsy, we wanted a more modern pattern similar to the way <div> overlays are done on the web. Imagine we have the following simple WPF app and when 'Click' is pressed a busy waiting overlay is shown for the duration entered into the text box. What I'm interested in here is not the actual UI element of the busy indicator but how I go about getting this to show & hide from when using MVVM. The actual UI elements are the standard Busy Indicator coming from the WPF Toolkit : The XAML behind this window is very simple, the important part is the ViewHost. As you can see the ViewHost uses a ContentPresenter element which is bound to the view model, IMainViewModel, it contains 3 child v

Custom AuthorizationHandler for SignalR Hubs

How to implement IAuthorizationRequirement for SignalR in Asp.Net Core v5.0 Been battling this for a couple of days, and eventually ended up raising an issue on Asp.Net Core gitHub  to find the answer. Wanting to do some custom authorization on a SignalR Hub when the client makes a connection (Hub is created) and when an endpoint (Hub method) is called:  I was assuming I could use the same Policy for both class & method attributes, but it ain't so - not because you can't, because you need the signatures to be different. Method implementation has a resource type of HubInnovationContext: I assumed class implementation would have a resource type of HubConnectionContext - client connects etc... This isn't the case, it's infact of type DefaultHttpContext . For me I don't even need that, it can be removed completely  from the inheritence signature and override implementation. Only other thing to note, and this could be a biggy, is the ordering of the statements in th