.NET client side debugging and profiling with Glimpse

Glimpse is a client side library for debugging and profiling, that you can install in your Visual Studio project with NuGet.

It is fully described in the following blog posts:


There are also extension to Entity Framework, to track database requests, and Elmah, already discussed in my other article .NET Health Monitoring with Elmah, that allows to add recorded exceptions in a new tab.


Finally, it's possible to develop custom tabs, described in this serie of articles:

.NET Health Monitoring with Elmah

Elmah (Error Logging Modules and Handlers for ASP.NET) is a Google library that you can find at its dedicated web site: Elmah - Error Logging Modules and Handlers for ASP.NET.

This library is used for Health Monitoring and allows to trace unhandled exceptions, logging them and, optionally, viewing them in a dedicated page.


This library is that it is implemented with a custom HttpModule, as described in the article Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components.

In this way, the installation doesn't require any code recompilation, as it is enough to add copy DLLs to the bin folder and add some web.config entries.


Finally, the last article ELMAH (Error Logging Modules and Handlers) with SQL Server Compact explains how to install and configure ELMAH with the Local SQL.

Lazy class in .NET 4

The concept of lazy is simple: sometimes creating a new instance of a class could be time-consuming, and you don't always need the full initialization of the class, but only a few members of it. So here we have the conpect of lazy construction: create or object, but complete the initialization only when all the fields are needed.

In previous versions of the .NET framework you had to implement this pattern by hand, but the .NET 4 introduces the Lazy class. The concept to build a lazy instances are simple:

  • define a private property containing the real value of the property you want to save (and don't initialize it), let's suppose you call it MyPropertyPrivate;
  • define your internal Lazy<T> property (let's say: call it MyPropertyLazy);
  • initialize the previous MyPropertyLazy as new Lazy<T>(() => { give a value to MyPropertyPrivate });
  • define a public property of type T, let's say called MyProperty, with a get accessor returning MyPropertyLazy.Value.

So in the end what happens is:

  1. a user access the public property MyProperty;
  2. MyProperty returns its value from MyPropertyLazy.Value;
  3. once "touched", MyProperty.Value evaluates the lambda expression,
  4. that finally executes and gives a value to MyPropertyPrivate.

Parallel programming in .NET 4 and custom TaskScheduler

.NET 4 introduces the concept of Parallel Programming. To simplify drammatically, its main concepts are:

  • Task: higher abstraction of Thread; conceptually, a thread is a way of accomplishing a task. Above all, you can cancel a Task (and its implementation should cancel the inner thread);
  • PLINQ: evolution of LINQ to allow parallel execution of LINQ queries.

You can get an introduction to the news of .NET parallel programming in the following two articles:

In my case I needed to create a custom TaskScheduler to handle priorities (like in Threads) for a custom queue management system. So, I got help from the following two articles:

ActiveDirectory query examples

If you need to query the ActiveDirectory, you have two ways:

C#: how associate string description to Enum types

If you need to associate string description to Enum types, you can add an attribute to each enum member, via the System.ComponentModel.DescriptionAttribute attribute.
So for example:
public enum MyEnum
[Description("desc A")]
[Description("desc B")]
Then, you can retrieve each member description with the following extension method:
public static string GetDescriptionFromAttribute(this Enum myInstance)
FieldInfo fi = myInstance.GetType().GetField(myInstance.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attributes != null && attributes.Length > 0)
return attributes[0].Description;
return myInstance.ToString();

Querying StringCollections with LINQ

If you need to query StringCollections, or other non-generic collection classes, with LINQ, you have to use the Cast method, so, for example:

StringCollection myStringColl = new StringCollection("AAA", "BBB", "CCC");

var query = from x in myStringColl.Cast<string>()...

Considerations developing SharePoint 2010 client applications

Here are a few considerations developing client applications accessing the SharePoint 2010 object model:

  • the target processor must be x64 (the default is x86 instead);
  • you need to use .NET framework 3.5 and not 4.0.

As noted in the post SP2010: SharePoint not supported with .NET framework version, these bugs were present since the beta of SharePoint, but they haven't been fixed yet.