Skip to content

Putting it out there…

Developing RegEx patterns

Recently I was creating some regular expressions. Because I’m not very experienced with RegEx, I was kind of “debugging” in my TDD approach. A colleague of mine recommended a website which helped a lot:

It’s completely free and you can use it online!


Before WCF, there was ASMX aka ASP.NET Web Services. Debugging ASMX or WCF are quite different. Let’s take a look how we can enable debugging in ASMX and WCF.

Basics of running a web application

When you hit the F5 button and your startup project is an ASP.NET, ASP.NET Web Services or WCF application, Visual Studio will start an ASP.NET Development Server. This is what we call Client-side hosting using Cassini. If want to know more check Dino Esposito’s article on MSDN. Wikipedia also has a description about UltiDev Cassini Web Server.

After Cassini is loaded, by default an Internet Explorer (IE) window will open and browse to the Cassini URL on your localhost.

Debugging ASMX

When you hit the F5 button, IE will open a webpage which looks like the image below:

Browse ASP.NET Web Service

Browse ASP.NET Web Service

You’ll notice that all Web Methods are listed as hyperlinks. So when I click “HelloWorld” in my example, it will browse forward:

Invoke ASP.NET Web Service

Invoke ASP.NET Web Service

Before we invoke the Web Method using IE, first we need to attach the Visual Studio instance with our sources to Cassini! In Visual Studio, navigate to “Debug” > “Attach to Process …”. In the list of Available Processes there should be a process called “WebDev.WebServer.exe” and the Title should be “ASP.NET Development Server – Port XXXX”. The Port XXXX is the port on which Cassini is active. Click the “Attach” button and you are ready to go!

Now, click the button “Invoke” in Internet Explorer and your Visual Studio will stop at the first breakpoint it encounters. When the method has returned its result, a new IE window will open and display the result as XML, like below:

ASP.NET Web Service Result

ASP.NET Web Service Result


Debugging WCF

Like ASMX, Visual Studio will open a browser by default:

Browse WCF Service

Browse WCF Service

At first it shows the directory listing. When you open your Service1.svc, you’ll notice that no hyperlinks or Invoke buttons are available on our Operation Contracts. To debug the WCF service, Microsoft provided a small tool in your Visual Studio installation directory, called “wcfTestClient.exe”. The tool is usually located in “C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\wcfTestClient.exe”. If not, you can download and install the Windows SDK from the Microsoft website.

In order to automatically start the “wcfTestClient.exe” and load our Services, we need to edit the WCF application project:

Start wcfTestClient.exe

Start wcfTestClient.exe

You can add multiple svc’s by leaving a space between the addresses.

When your WCF Service is loaded, you can double click an Operation Contract and invoke it. You don’t need to attach your Visual Studio to another process, it’s already attached for you.

wcfTestClient Method Invokation

wcfTestClient Method Invokation


When you’re working with a UI or plain text data integration, conversions are often an issue. In this case I would like to talk about DateTime objects.

Recently, there was an issue in one of the other teams. They had a WinForms UI where they wanted to display a DateTime property in two different textboxes, one for the date and another for the time. They had their reasons for not using a DateTimePicker control or any other method. That wasn’t really the problem. One of the business users discovered an error when trying to save changes. The development team figured out what went wrong, apparently it was a “Culture” thing.

The business user’s computer was using Windows XP and its regional settings were set to English – United States. When the application tried to parse the textboxes and store the value back in the property, the month and day were swapped. In Europe we usually use “dd/MM/yyyy”, in the US they use “MM/dd/yyyy”.

Normally this should not pose a problem, the date was successfully loaded, so why wouldn’t it convert back as expected. Well, one of the main reasons is VB.NET. VB.NET has a feature called CDate, which can convert a string to a Date object. In C#, you only have a DateTime object. What happened? The CDate takes the regional settings and when you enter 16/10/2010, it will crash, because there is no 16th month.

Enter Mike

I overheard an intense discussion going on and decided to see if I could be of use. Call it interfering if you want; I see it as helping colleagues ;) . They explained the situation of the custom controls (the two textboxes) and the error. One of them was telling they needed to use DateTimePicker controls, another wanted to change regional settings in the database and application (I missed the point of that one), and so.

After a bit of evaluating, I noticed they were only complicating the solution/problem. I told them they only needed to parse the string into a DateTime object with specific format, and then assign the DateTime to the Date object. So instead of doing a lot of changes, add a single line of code…

I created a helper/utility class on the fly, so they could end their discussion and get back to work (and stop bothering the rest of us :) ).


using System;
using System.Globalization;

namespace MyNamespace
    public static class DateTimeParser
        public static DateTime ParseDateTime(string value, string inputFormat)
            return ParseDateTime(value, inputFormat, CultureInfo.InvariantCulture);

        public static DateTime ParseDateTime(string value, string inputFormat, CultureInfo provider)
            if (string.IsNullOrEmpty(value))
                throw new ArgumentNullException("value");

                return DateTime.ParseExact(value, inputFormat, provider);
            catch (Exception ex)
                throw new Exception("Could not parse date: " + value, ex);

	public class DateTimeParserDemo
		public DateTime Test()
			string myDate = "31/12/2010 23:59:59";
			return DateTimeParser.ParseDateTime(myDate, "dd/MM/yyyy HH:mm:ss");


VB.NET code

If you prefer the code in VB.NET head to the website of, they have an excellent C# to VB.NET converter.


Lately I’ve been listening to some MP3 songs on my corporate laptop. Today I noticed that the library of Windows Media Player (WM Player) was getting pretty big. I don’t want my corporate laptop to contain a lot of information about my music. So I was looking for a “clear” button or menu item but didn’t find any. Because I don’t usually use WM Player as an MP3 player, I don’t really know all the features and options. Let’s go and take a look.

Quick solution

If you want to delete the entries in the library, close your WM player and navigate to “C:\Documents and Settings\YourUserNameGoesHere\Local Settings\Application Data\Microsoft\Media Player”. Found it? Close your WM Player. Now delete all the files in the folder! Restart WM Player and you’ll see that the library is empty.

continue reading…


Unfortunately, there is no easy way to create a fully qualified XML file. The problem is that a rolling file appender writes its entries sequentially. As we all know, an XML file has to start with opening a root element and end with closing the root element.

Of course, we can always provide some kind of workaround.

continue reading…


I wanted log4net to write its log entries in a SQL Server database. log4net’s AdoNetAppender would have done the trick. But, there are three requirements I need to keep in mind.

  1. I have to use my logging framework
  2. The connectionstring has to be stored the app.config or web.config
  3. The machine’s hostname has to be added to the log entry

continue reading…

What is log4net

If you have never heard about log4net, this article isn’t immediately suited for you. Dimitri Clement wrote a few articles about log4net and how to use it:

You can also visit the log4net website.

continue reading…


Every developer knows that managing your app.config or web.config isn’t an enjoyable task. When you’re moving your application from one environment to another, you will need to change some variables. Maybe you’re working with automatic builds, and so on.

Since Visual Studio 2010 you have a new feature: “Config transformations”. Because I’m still working with Visual Studio 2008, I can’t use it. That’s why I wrote my own config transformer.

continue reading…

Announcement: “CLR via C#” blog series

A friend and colleague of mine and I decided to give several knowledge sharing sessions based on the book: “CLR via C#” by Jeffrey Richter. More info about the book at Microsoft Learning.

We believe it is a very good book, but hard to process. It’s not something you call “light reading”. That’s why we like to redeliver the book to the MSCoP group of Capgemini. Of course, we won’t forget our blog readers! We’ll put all our materials (slides and code samples) online.

We’ve limited our delivery to 4 sessions, one per month. Because we cannot cover the whole book in our sessions, we decided to occasionally blog about the remaining parts of the book.

Session Agenda

Session 1 (End of September)

  • Chapter 1: CLR Execution Model
  • Chapter 2: Building, Packaging, Deploying, and Administering Applications and Types

Session 2 (End of October)

  • Chapter 21: CLR Hosting and AppDomains
  • Chapter 3: Shared Assemblies and Strongly Named Assemblies
  • Chapter 22: Assembly Loading and Reflection

Session 3 (TBA)

  • Chapter 19: Exceptions
  • Chapter 23: Performing Asynchronous Operations
  • Chapter 24: Thread Synchronization

Session 4 (TBA)

  • Chapter 20: Garbage Collection

The problem

Today I wrote some tests for a project I’m working on, which uses the FileHelpers library.

When I tried to run the tests, I received the following error:

Failed to queue test run ‘mbev@WSXP-BE-6833 2010-08-31 11:51:43′: Test Run deployment issue: The location of the file or directory ‘c:\pathToProject\business.tests\bin\debug\FileHelpers.dll’ is not trusted.

First thing that went through my mind was: “Man, I’m trying to introduce testing in this environment and then I get this. Why is everything working against me?!!”. Nevertheless, I put my personal issues aside and worked on resolving the problem.

In the past I’ve encountered a similar issue, but then I was working with network shares. Visual Studio has trust issues with other machines then your own. It that were the case, you can resolve it using CASPOL (Code Access Security Policy Tool). But I’m working on my own machine, on a local drive, my system drive!

The Solution

Suddenly, I remembered that Windows also has trust issues with external dll’s and exe’s. The solution is extremely simple! You can resolve it by clicking two buttons: Unblock and OK…

Restart Visual studio and you’re good to go!

Filehelpers Properties - Blocked