Technology Tamed

  • How to Find Application Pool by Process ID from within Visual Studio 2012

    7/17/2013 10:31:46 AM by tristan

    it’s always frustrating when commencing a debugging session of an IIS hosted application in Visual Studio having to try and identify which worker process to attach to when you have multiple sites running.

    Attaching the debugger

    To identify which process to attach to, I’ve long been a fan of the command “appcmd list wp” to find out which process ID is which application pool when debugging within visual studio;

    appcmd list wp

    More recently I got fed up with having to switch out of visual studio to my console window to run the command only to switch back into Visual Studio to get the debugger attached.

    There had to be a better way. A way to execute the command from within Visual Studio.

    In Visual Studio 2010 there was PowerConsole, a gallery extension that gave a Powershell prompt from within Visual Studio, but it isn’t supported in Visual Studio 2012. Researching further I came across a post on Stack Overflow related to Poweshell inside Visual Studio.

    The second answer gave me an interesting lead;

    “The NuGet Package Manager has a NuGet Package Manager Console which is a PowerShell host. Open the console by clicking Tools > Library Package Manager > Package Manager Console.”

    I didn’t know that. Interesting.

    Sure enough, a swift powershell command later;

    $appCmd = "$Env:SystemRoot\system32\inetsrv\appcmd.exe"
    &$appCmd list wp

    Package manager console

    Voila. Problem solved. Now I can quickly resolve the process ID of the application without having to leave visual studio. Happy days.

  • Book Review - Clean Code: A Handbook of Agile Software Craftsmanship

    5/5/2013 10:59:38 AM by tristan

    Clean Code: A Handbook of Agile Software Craftsmanship by Robert C Martin, Published 1 Aug 2008

    Clean Code Robert Martin aka  “Uncle Bob” is a well known and well respected figure in the software development industry. He introduced the development world to SOLID in his principles of OOD article over ten years ago in 2003 and continues to publish, talk and teach software development. 

    This book is firmly aimed at developers, It’s low level in the vein of Steve McConnell’s Code Complete and that’s a really good thing.

    The book is presented in three distinct section. The first thirteen chapters deal in detail with common problems found in code, how to avoid them in the first place and how to deal with them when they’ve already occurred.

    The second section dives into three examples of successive refinement/refactoring on some real life code, illustrating the application of the principles covered in the first section.

    The third and final section provided a reference encyclopaedia of code smells and heuristics, nicely summarised in this “clean code sheet sheet”.

    The overriding message of the book is that as professional software developers we have a responsibility to “leave the campground cleaner than we found it”. This Boy Scout Rule is a great ethic. As a professional coder it’s not enough to “not make it any worse”, we all need to actively work to maintain our codebases and constantly strive to make them a little bit better through a process of constant refinement.

    All of the code presented is in Java although most of the principles covered are applicable to any OO language and many of them to all languages.

    In summary, Clean Code is a great book dealing with the nuts and bolts of practical everyday software development. I’d highly recommend it to any intermediate developer as a must read to help take their coding skills up a level. More experienced developers will have learnt most of the lessons the hard way through their own experience, however the book still provides value as a refresher and reference to common pitfalls and their solutions. I’m looking forward to reading the sequel, The Clean Coder: A Code of Conduct for Professional Programmers.

  • Miniprofiler, MVC and NHibernate

    4/20/2013 11:58:00 AM by tristan

    I’m unfashionably late to the party on this one. Whilst reading Professional MVC4 recently, Phil Haack mentions a NuGet package called MiniProfiler which his team found helpful in the development of the NuGet gallery. I made a mental note to have a look at.

    I’m not quite sure how I managed to miss this before as both Scot Hanselman previously blogged about this in his post NuGet Package of the Week #9 - ASP.NET MiniProfiler from StackExchange rocks your world as did K Scott Allen in ELMAH and MiniProfiler In ASP.NET MVC 4.

    The Essentials

    MiniProfiler was designed by the development team at Stack Overflow. It’s a simple but effective in browser mini-profiler for ASP.NET, WCF and the .NET platform. Once installed and properly configured, MiniProfiler adds a little widget to every page on your site when running in localhost. This widget initially indicates the time taken by the server to process the request ;

    Mini Profiler Widget

    Click on the widget and you’ll get profiling information for the current page. For example, below you can see that the a request to this site’s book review of dependency injection in .Net ran 5 SQL queries and spent 23.8% of the execution time in that SQL. 

    Mini Profiler Trace

    As a developer, Miniprofiler raises your awareness of what SQL statements are actually being executed. MiniProfiler will expose this information to you. Simply click on the “sql” links to see the generated SQL, as well as the containing method, as shown below. 

    Mini Profiler SQL Trace

    Adding support for MVC

    Adding the NuGet package MiniProfiler.MVC3 adds much better support for MVC applications by adding timing information for certain key points in the request life cycle, such as rendered views and partial views.

    Inviting NHibernate to the party

    NHibernate is a fabulous ORM, but it can have a tendency to disconnect the developer from thinking about the underlying SQL being generated and executed. definitely. NHibernate Profiler is great for this in a full on profiling/debugging session, but wouldn’t it be great to have this information more readily available?

    Out of the box MiniProfiler won’t integrate with NHibernate, but fortunately, there’s a NuGet package for that! Just install MiniProfiler.NHibernate and then configure our NHibernate session to use this connection driver;

    cfg.SetProperty(Environment.ConnectionDriver, typeof(MiniProfiler.NHibernate.MiniProfilerSql2008ClientDriver).AssemblyQualifiedName)


    I don’t envisage that you’ll be replacing either dotTrace or NHibernate Profiler any time soon for detailed profiling/debugging, but to give you a quick overview of what’s going on Miniprofiler + MiniProfiler.MVC3 + MiniProfiler.Nhibernate is giving me a warm feeling thanks to these features;

    • Quick obvious performance information at your fingertips
    • Unobtrusive enough that it won’t annoy
    • Always present on the developer’s local machine so encourages some thought to be given to performance
    • Attractive, functional UI
    • Configurable if required to be enabled for remote access on production servers by user/role

    It’s now installed on my current client’s codebase and is already helping the multi developer team improve the performance and efficiency of the codebase. I recommend you use MiniProfiler on your project. For The Win.