Category: Tools

Error handling using aspect-oriented programming (AOP)

Code become’s messy with error handling logic all over our code, wouldn’t it be nice to be able to log the error, the offedning method name and the line number of the code that caused the error in the first place.

If you’ve done any MVC development then you are already familiar with AOP, [HandleError] is an example of an aspect and with very little effort indeed you can create your own. Creating an aspect means you can reuse logic for tracing, error handling and more very easily.

At work we use PostSharp for our AOP aspect-oriented programming and its doesn’t get much easier. The guys even give you an add on in visual studio and it walks you through how to go about learing AOP and how to create aspects using PostSharp – the tutorial is superb and very well thought out.

We have a class library logging class which we use as an aspect using Postsharp and this means that we can add a [Catch] attribute to the method and we now have error logging for this new method:-

[sourcecode language=”csharp”] [Catch] public MyNewMethod()
{
throw new applicationException();
}
[/sourcecode]

And that is it, download the demo and give it a try its so easy but quite powerful – I recommend you take a look.




AspConf – My Review

Last week we had AspConf – “aspConf is a virtual conference focused on one thing: showcasing the ASP.NET stack as the platform for great web applications.

Over 2 days they had 5 virtual rooms used to present lots of fascinating stuff on .Net, including talks about all manner of things in the Asp.Net world.

The sessions on both days covered topics such as, Async in .Net 4.5, Glimpse, TDD, Azure and Cloud Computing and lots lots more, you can read more about the sessions here.

Although it had some technical difficulties, due to its popularity I may add, the conference is an awesome way to learn for free – and free is always good. It’s a superb way to learn about content you havent had time to look at it, or new technologies you havent heard of. Hopefully next year they might try to use something different from livemeeting.

If you missed any of the session then fret not, most of them if not all of them were recorded and put up on Channel 9 here

I only managed to see sessions from day 2 so I am off to go watch more content on Channel 9 – a great resource for free learning.



Twitter Bootstrap – What is it?

What is it? – If your creating a new web project and want it to start off on a good footing using HTML 5, CSS, JQuery, templating, boilerplates and all that’s generally good for a new or existing project then this is for you.

Twitter bootstrap comes with layouts and templates to use all built for you using best practice web standards. Recently it has received a fair bit of attention and there are a large number of people using it out there.

BootStraper1

What does it contain? – html templates and boilerplates to get you started, JQuery plugins for a number of things, thumbnails, progress bars, all sorts of navigation aids such as tabs, pagers and label and much, much more.

BootStraper2

You can learn more and download it from the official site here.

If you like twitter bootstrap then try this too:- Initializer

Initializer

How many of you are using it? – have you come across any other useful bootstrap projects? – If so please leave me a comment.



Fusion Log Files are your friend

Firstly this is a very handy tool that a lot of people are unaware of I certainly was, wish I had known about this when trying to fix ClickOnce issues a few years back.

Today I ran into an issue where a small windows forms application was throwing weird exceptions upon start-up, I also had the misfortune of Nuget.exe throwing a tantrum and a colleague asked me had I tried using the Fusion log viewer.

I had a vague idea what it was and remember seeing that mentioned in the event viewer error logs before, but didn’t know much more about it.

The following is how to go about enabling logging for when Visual Studio starts throwing weird errors upon loading up an application.

  1. First of all click Start, and then type in Fusion Log Viewer into the run box, and then right-click on it and run it as an Administrator.

    FusionLog

  2. This will bring up the following:-

    FusionLog
  3. Click settings and here we enable logging and give it a directory path to save the files to.
    Note that the folder needs to be created first, before it will let you give a path:-

    FusionLog
  4. Run the offending app-add in and the log files will be write to the folder you specified.
  5. Upon investigation of these files they usually have a file per missing or wrong assembly, they give you some insight into whats missing as well as the correct version number the code requires.
  • For more info check out Scott Hanselman’s post on this here
  • Let me know if this helps you or any questions then please add a comment.



    RavenDB Useful Tools

    Here I will list all of the useful tools I come across when using RavenDB.

    So here is the list:-

    • RavenDB add on for Glimpse Glimpse RavenDB.
    • RavenDB Mini Profiler – more info can be found here and here.
    • LinqPad which can be found here is a great tool which you can use to query RavenDB using Linq statements – if you have the correct third party driver installed.

      To learn how to get Linqpad to query RavenDB you will find all you need to do here.

    • Rest-Client which can be found here is extremely handy for testing Restful webservices which RavenDB is.

      RestClient

      Click the downloads tab and then select the following:-

      RestClient

      Once selected rest-client will fire up, it’s very straight forward to use, put in the url to your database where RavenDB is running and then you can use the POST, GET and so on as below:-

      RestClient3

    • Fiddler 2 which can be found here

      Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect traffic, set breakpoints, and “fiddle” with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language

      We can use Fiddler to monitor what is going on when we work with RavenDB as well as use it to inject documents on the fly which is shown in the Tekpub video series.

    • If anyone has any other useful tools for working with RavenDB then please let me know and I will add to this list.




    Real World MVC 3 Development

    During the last couple of months I have been working with MVC 3 daily and I have used Nuget packages and tools which have helped in a number of areas, in this post I will give a shout out to these tools which help make MVC 3 a pleasure to work with. For the most part Nuget packages can be found for these tools so you can add them very easily and get going quickly.

    Routing

      • Attribute routing for MVC – Remove any routing concerns/issues and start using this now.
      • T4MVC helps make your MVC code much more maintainable, enough said.

    Page Performace

        • Chirpy is an open source Visual Studio Add In For Handling JavaScript, Css, DotLess, and T4 Files, which in essence improves page performance.
        • Cassette – Cassette automatically sorts, concatenates, minifies, caches and versions all your JavaScript, CoffeeScript, CSS, LESS and HTML templates.

    Profiling

        • Mvc Mini Profiler – A simple but effective mini-profiler for ASP.NET MVC and ASP.NET.
        • Glimpse – What Firebug is for the client, Glimpse does for the server… in other words, a client side Glimpse into whats going on in your server.

    Error Logging

        • ELMAH – ELMAH (Error Logging Modules and Handlers) is an application wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment

    All MVC posts

          • All of my MVC blog posts can be found here.

    Conclusion

    MVC is great to work with on its own but these tools can only enhance the development process. Please leave feedback or comments, and also let me know if I have missed out on any tools which I can add to this list.



    MVC – get some help

    If you’re using MVC and you’re looking for some in-depth information on basically whats going on when you run the code then you should take a look at Miniprofiler (from the guys at StackOverflow) or Glimpse.


    Miniprofiler can be added in to your solution and can give you all sorts of really useful information such as which view is currently being rendered and from which method in the controller (which is not always obvious). this can be quite a time saver if you’re not used to the codebase and just want to quickly find the ActionResult which has been hit.

    To Add MiniProfiler to an MVC application install it using the Nuget Package Manager console. (you need to use the console sometimes if the package uses a Powershell script)

    Once added via Nuget browse to your global.asax file and add in the following 2 methods:-

    [sourcecode language=”csharp”] protected void Application_BeginRequest()
    {
    if (Request.IsLocal)
    {
    MiniProfiler.Start();
    }
    }
    [/sourcecode]

    and then :-

    [sourcecode language=”csharp”] protected void Application_EndRequest()
    {
    MiniProfiler.Stop();
    }
    [/sourcecode]

    Rebuild your code and run your application and you’ll see info being displayed by MiniProfiler in the top left hand corner as follows:-

    Glimpse


    Glimpse is a JavaScript plug-in which informs you of information such as Route Debugging which is a superb feature. Add Glimpse via Nuget and then browse to your site and add /glimpse.axd to the end of the url from your application:-

    Glimpse

    Pres enter and you’ll be taken to this screen, this nice bit here is you can drag the ‘Turn Glimpse On’ and ‘Turn Glimpse Off’ to your fav bar and just click them to do as it says on your site. (This is all done in JavaScript and has very little overhead)

    Glimpse

    After clicking on ‘Turn Glimpse On’ we see the little eyeball bottom right of the screen:-

    Glimpse

    When clicking on that you’ll see something like the following:-

    Glimpse
    Here we can drill into all sorts of information such as:-

    • What route has been called
    • Which view has been rendered
    • Time spent to render the page and timings for each part
    • Config on the server

    Again go get them and you’ll have them up and running very quickly and benefit from the features they come with.



    Chirpy for MVC

    Chirpy is an open source Visual Studio Add In For Handling JavaScript, Css, DotLess, and T4 Files.

    Better Page Performance
    When you validate your site against YSlow it gives you reports on why your webpages may take some time to render in the browser – Chirpy can help with this big time by minifying script files like javascript, css and more so that there are less requests made to the server on each page request – better page performance is always good.

    YSlow

    The full list of what Chirpy can do can be found here.



    MVC 3 useful Tools

    Having be doing some MVC 3 work recently I have used the following tools and I highly recommend every one of them if you are doing this type of work.

    • Mvc Mini Profiler – A simple but effective mini-profiler for ASP.NET MVC and ASP.NET.
    • Glimpse – What Firebug is for the client, Glimpse does for the server… in other words, a client side Glimpse into whats going on in your server.
    • Cassette – Cassette automatically sorts, concatenates, minifies, caches and versions all your JavaScript, CoffeeScript, CSS, LESS and HTML templates.
    • ELMAH – ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment

    Please take a little bit of time to look at each of these tools – they are all free and are fantastic.



    Removing Unused Project References from within Visual Studio 2010

    I have always wanted to know if there was a tool for looking at a project and removing any unused project references within a .net application. On twitter I came across a tweet from @dotnetjunky where he mentioned this project. Ref Assistant

    It’s also available within the Visual Studio Gallery incase you want to add it from there. Once installed you can right-click on References and then select ‘Remove Unused References’ as below:-

    Unused References ScreenShot

    Once installed this will be available within any Visual Studio project you open as long as it is used within Visual Studio 2010.