Beware of .NET 4.6 Workstation GC

Saturday, August 8, 2015

TL;DR: Changes in the .NET 4.6 Workstation GC has made it much slower for us. We had to make sure our tests are using the Server GC mode. VS 2015 came out and we happily upgraded. Everything worked great, except for one thing: our integration tests started to run slowly. Like 10 times slower. The thing is, the same code, when not running under the NUnit process, worked just fine. Something was afoot. After much investigation and profiling, we discovered the root cause: GC. Our integration tests run our entire system start-up process, which allocates a few gigs of...
no comments

The Case of The Async Log4Net Appender

Wednesday, October 16, 2013

It was a bad day. I was coding away happily as we started getting alerts that one of our production farms is down. Our service seemed to be stuck on each one of our servers. Requests are coming in, but no responses appear. Restarting the service helped, only to get stuck again after a while. The logs were unhelpful, and we had to pull out windbg to figure out what was going on. When your day starts with windbg, you know it won’t be a good one. The command ~*e!clrstack (=view stack trace of all managed threads) showed...
4 comments

How to Save a Unicode Text File That Excel Can Read

Sunday, 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...
tags:
2 comments

Sets of Mutable Objects is a Bad Idea

Thursday, 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...
tags:
3 comments

Improving Upon LINQ’s Distinct

Saturday, August 1, 2009

Suppose you have a collection of objects, and you want only the distinct values. You could easily use Linq for this, like that: var items = new {"BMW","Fiat","Ferrari","Fiat"}; var distinctItems = items.Distinct(); This uses the default comparer for the objects in order to see if they’re equal. There’s also another overload, which lets you specify your own comparer. This is its signature: public static IEnumerable<TSource> Distinct<TSource>(this IEnumerable<TSource> source, IEqualityComparer<TSource> comparer); It accepts an IEqualityComparer to compare between items. But the usage of IEqualityComparer is...
tags: ,
2 comments

Pretty Quick Sort With C# 3.0

Thursday, January 29, 2009

Jafar Husain writes about the prettiness of F#'s type inference, but what I really liked in his post was his C# 3.0 implementation for Quick Sort: 1 public static IEnumerable<T> QuickSort<T>(this IEnumerable<T> list) 2 where T : IComparable 3 { 4 if (!list.Any()) 5 { 6 return Enumerable.Empty<T>(); 7 } 8 var pivot = list.First(); 9 var smaller = list.Where(item => item.CompareTo(pivot) <= 0).QuickSort(); 10 var...
tags:
6 comments

Interesting Behavior with the New Modifier and Interfaces

Saturday, February 9, 2008

Consider the following code. What will be the result of calling Test.TestInterface()?     public interface IInterface     {         void DoSomething();     }       public class Father : IInterface     {           public void DoSomething()         {             Console.WriteLine("Father Called");         }       }       public class Son: Father     {         public new void DoSomething()         {             Console.WriteLine("Son Called");         }     }       public class Test     {         public void TestInterface()         {             IInterface tester = new Son();             tester.DoSomething();         }     } Note that Father is...
tags:
no comments

Don’t Seal That Door

Friday, January 11, 2008

I've been going over this week's updates, and ran across this post in CodeBetter, that talks about why classes should be sealed by default, only to be unsealed by the 'unsealed' keyword. I couldn't disagree more. I think that you need a hell of a good reason to seal a class, so claiming that most classes should be sealed is a bit seems outrageous to me. I believe it's absurd to prevent extensibility for your classes, and if classes are sealed by default, the result will be, obviously, a lot more sealed classes around. After all, unless you plan...
tags: ,
2 comments

C# 3.0 New Feature for the Week #6: Partial Methods

Saturday, December 22, 2007

This is a feature I was completely unaware of until I started digging into Linq-to-SQL recently. Upon using the Linq class designer on the Northwind database, I looked into the generated code, and saw something like this: public partial class Category { partial void OnCreated(); public Category() { //Do stuff ...
tags: ,
3 comments