Unit testing databases

Here’s a cool tool on CodePlex that Tim pointed me to for anyone who needs to write unit tests on your data-access code: http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=MassDataHandler “The MassDataHandler is a framework to assist with Database Unit Testing. The framework makes it very easy to insert test data into a database, which in turn makes it very easy…

1

Possible slowdowns under a debugger

Here’s a list of things that may slow down execution under a debugger. I’ve seen a few threads go by about ways that running under the debugger significantly slows down normal execution by more than 2x, and this is a collection of those items.  Background:Stepping through each statement (F10) runs significantly slower than just running…

2

Writing an RTF to HTML converter, posting code in blogs.

Visual Studio’s IDE will copy code as RTF (Rich Text Format). Web browsers like HTML. So posting code from Visual into blogs means a decent RTF to HTML conversion. And having a technical blog means posting code.  So I needed to solve this conversion problem. The sad tale:At first I tried Word, but Word had…

12

Questions you should ask before using a callback / delegate

I just got burned by using callbacks in a multi-threaded app. I’ve rewritten the part to avoid callbacks, but for my good-deed-of-the-day, I wanted to issue a word of warning. Before you can safely use a callback / delegate / virtual function, particularly in multi-threaded code, you should answer the following questions: Do I hold…

5

Using Foo<T>(…) instead of Foo(System.Type, …)

Whenever you’re passing in a parameter of System.Type that is usually determined at compile-time, consider having a version with a generic parameter.  This converts runtime checks into compile time checks, may let you have more efficient code, and likely lets you get rid of ugly casts. For example, a method like: static object Enum.Parse(Type enumType,…

8

GCHandle.ToIntPtr vs. GCHandle.AddrOfPinnedObject

Both GCHandle’s ToIntPtr and AddrOrPinnedObject take in a GCHandle and return an IntPtr. I had to do a double-take to remember the difference between them, so I’d thought I’d blog about it. GCHandle.AddOrPinnedObject is for passing the address of the object through unmanaged code, and it requires the object is pinned.That address could then be…

0

Pop quiz: Who wins in finally vs. return?:

Question 1) What’s the return value from this C# function: static int Test() { int val = 1; try { return val; } finally { val = 2; } } Question 2)  What about this (using a static instead of  local) static int s_val; static int Test() { s_val = 1; try { return s_val;…

8

Debugging Ngen code

You can debug ngen (aka prejitted) code from VS2005 and also have the VS2005 IDE launch ngenned code. In practice, images are rarely ngenned as debuggable. And usually when under a debugger, assemblies are loaded with debuggable code-gen flags (In VS, this is the default).  Thus it’s rare to load ngenned images when under a…

3

ICorDebugValue vs. System.Object

System.Object represents a managed object within a process. ICorDebugValue is the debugger’s representation of a System.Object within the debuggee process. The key here is that the debugger and debuggee processes are ideally fully isolated from each other. For example They could both be running different versions of the runtime. The debugger should not be “tainted”…

3