TransactionScope & SqlConnection not rolling back? Here’s why…

A while back we ran into an issue with one of our projects where we executed a erroneous query (missing DELETE statement), and then left the database in an inconsistent state. Which is weird, considering the fact that we use a TransactionScope. After some digging around I found the behavior I wanted, and how to […]

About a dictionary, removing and adding items, and their order.

I had a weird problem today using a Dictionary. The process involved removing and adding data, and then printing the data. I assumed that it was ordered. I was wrong! Let me show you: var dictionary = new Dictionary<int, string>(); dictionary.Add(5, “The”); dictionary.Add(7, “quick”); dictionary.Add(31, “brown”); dictionary.Add(145, “fox”); dictionary.Remove(7); // remove the “quick” entry After a […]

Make sure unattended.xml is not encrypted!

I was playing around with Sysprep using unattended.xml when I hit a weird issue with VirtualBox and Encrypted folders on the host. Setup: unattended.xml on the host, encrypted (with Windows EFS). Virtual Machine, hosted in VirtualBox I mounted the folder with unattended.xml (and other files) inside the VirtualBox and started sysprep (sysprep+shutdown.cmd just executes the […]

Foreach now captures variables! (Access to modified closure)

Foreach has changed in C# 5.0! Consider the following piece of code in C# < 5.0: public class Test { public static void Main() { var words = new[] { “foo”, “bar”, “baz”, “beer” }; var actions = new List<Action>(); foreach (string word in words) { actions.Add(() => Console.WriteLine(word)); } actions.ForEach(e => e()); } } […]

When using an enum in PowerShell, use the member’s name, not the member’s value

Consider the following enum in C#: enum State { Started, Stopped, Unknown } Note that I have not added an explicit value for the enum members. They will be generated by the compiler. As stated in the C# spec: … its associated value is set implicitly, as follows: If the enum member is the first […]