Microsoft® SQL Server® 2008 R2 SP1 Feature Pack CTP1.
Scott Hanselman wrote a blog post called Request for Comments: Issues with .NET and Microsoft Product Versioning. He welcomes your feedback either in his blog comments or a Twitter Poll for you to spread around.
Interesting fact that I discovered today: usually, static field initializers run whenever the parent type is first loaded. However when you ngen the assembly, apparently you can load the type and work with it – static field initializers will only be executed immediately before you actually access the field.
I’ve run into this by having a static Stopwatch timer = Stopwatch.StartNew(); in one of my types. It was supposed to measure an application’s startup time, but I noticed that after NGEN’ing the assembly the timer always returned a value close to 0.
Here’s the code to verify this behavior:
private static int field = Initialize("Field initializer");
static void Main(string args)
field = 1; // touch the field
private static int Initialize(string message)
Console.WriteLine(message + ": " + DateTime.Now.Ticks.ToString());
This works the same for .NET 4.0 SP1 for Debug/Release and x86/x64. I didn’t try other frameworks/OS/platforms.
Here’s the output from the console:
Field initializer: 634462768999291588
Field initializer: 634462769013544438
E:\>ngen install NgenedStaticFieldInitializers.exe
Microsoft (R) CLR Native Image Generator - Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Installing assembly E:\NgenedStaticFieldInitializers.exe
1> Compiling assembly E:\NgenedStaticFieldInitializers.exe (CLR v4.0.30319) .
1>NgenedStaticFieldInitializers, Version=188.8.131.52, Culture=neutral, PublicKeyToke
Field initializer: 634462769095660858
Field initializer: 634462769108933512