NuGet Annoyance

May 29, 2012

I usually love using NuGet, but there are things about it that can sometimes make me scream with annoyance. My main issue is with the following scenario: I want to add a new dependency to a project. This dependency already exists in the solution. Here, one of two things may happen: The version that exists in the solution is the newest that came out. In which case, no problemo, NuGet will see that I already have that package installed and use it. A...
no comments

ThreadAbortException is Special

February 7, 2012

*Update (27/8): It is critical to set the time below to AutoReset = false, otherwise, the exception might be raised again, even after we handled it. I guess you could say that every exception is special and important in its own way, but ThreadAbortException is really special. In what way, you ask? Well, let me tell you a story. I wanted to implement a hard timeout for our system. That is, if a query to our service takes too long, force kill it, not matter what it is doing at the moment. You may claim that this...

Tip for Profiling NUnit Tests

December 15, 2011

This is just a tiny little note that can save you some precious time. This article explains exactly what you need to do in order to profile NUnit tests with dotTrace (gotta love products with special placement of capital letters) 4.0, except it misses an important detail. The latest versions of NUnit run the actual tests in a separate process, called nunit-agent.exe. So, if you profile nunit-console.exe you won’t see your code there at all. You have to run NUnit in a single process mode. To do that just add /process:Single to the nunit-console command line arguments, and everything...
no comments

How to Save a Unicode Text File That Excel Can Read

December 11, 2011

The other day I had to create a .CSV file with some funky Unicode characters. Not only that, but Excel had to be able to open and edit it. When using .NET’s StreamWriter default constructor, it uses a default encoding of UTF-8 without BOM (byte order mark), which Excel can’t read. Well, actually, it can read it, but it doesn’t realize that this is a unicode file and special characters (such as this lovely one - Ž) have a tendency to look like someone just puked a letter on the screen. The solution is quite...

A Trip to Java Land

November 13, 2011

I’m a C# guy, and always have been. I haven’t done any Java-ing since my days at the university, so I was glad of the opportunity to a do Java-related task at work. It was really a tiny little thing, but I got a little taste of the state Java is in and thought I would share. Now, I’m hardly objective, and I’m basing this on a few hours of work tops. Also, any criticism I have is against Java the language, not Java the Framework. So, with the disclaimers out of the way, let the rant...
no comments

Visual Studio x64 is Not to Be

November 3, 2011

I was informed today that a Visual Studio user voice issue I voted on was dismissed. The issue is “Create an x64 version of Visual Studio”, and around 1300 people voted for it. Sadly, Microsoft decided it’s not going to happen any time soon. Visual Studio’s program manager, Nathan Halstead, explains: After reviewing telemetry on memory utilization, the scale of typical data sets loaded in Visual Studio, and hardware trends across our user base, we determined that one of the most effective ways to improve memory utilization across our entire user based would be to...

Sets of Mutable Objects is a Bad Idea

October 27, 2011

I guess this is something that is obvious to many, but it really had me stumped yesterday. I was looking at code that was joining two HashSets, that both had the same item. Not the same reference, but they had the same hash code, and Equals between the items returned true. And yet, Set1.UnionWith(Set2) changed Set1 to have two items. That seemed insane. Isn’t it in the contract of HashSet to not contain the same item twice? How could it be? It took a while, but I figured out the issue. Let’s try to recreate a situation where a...

Inheritance is Truly Evil

October 25, 2011

Lately I’ve been refactoring some really old code, and it helped me realize that in about 90% of the cases, inheritance from a class (unlike interface implementation) is a Bad Thing. Of course, I’m hardly the first to think that, but it’s not until I had to refactor deep, and absolutely wrong, object graphs until I felt it in my bones. But why? Isn’t inheritance a legitimate way to reuse code? Well, no, for several reasons: It makes the code harder to understand. To understand the flow of your class, you...
no comments

Why doesn’t ConcurrentBag implement ICollection<T>?

May 4, 2011

Hopefully you’ve encountered by now the System.Collections.Concurrent namespace. It’s new to .NET 4, and it has many useful data structures which are optimized for multi-threaded usage. ConcurrentBag, for instance, is an unordered collection of objects, which multiple threads can add and remove objects from at the same time. Recently I needed to test that some piece of code was thread-safe. To do that, I wanted to run it once synchronously, and once asynchronously. It looked something like that: 1: private static IEnumerable<ComputationResult> ComputeSynchronous(IEnumerable<string> inputs) ...
no comments