App Config’s root element should be namespace-less

The root element for Application config file is <configuration> <?xml version="1.0" encoding="utf-8" ?> <configuration > </configuration> The application config file is shared with CLR and Windows SxS. SxS dictates that the root element is <configuration>, and it should be without namespace. If the application config file does not follow the rule, SxS will refuse to…

0

Calculating the size of each GC generation

Sos.dll does not have a command to tell the size of each GC generation. However, you can calculate the size based on the output of !eeheap -gc. For example, 0:000> !eeheap -gc Number of GC Heaps: 1 generation 0 starts at 0x1da6c430 generation 1 starts at 0x1da5c240 generation 2 starts at 0x01a41000 ephemeral segment allocation context:…

2

Figuring out object allocation graph from a managed memory dump

  when debugging a managed memory dump, we can use Sos.dll to inspect managed objects inside the dump. for example, we can do !dumpheap to list the managed objects in GC Heap, we can also use !gcroot to figure out the reference path to a particular object. However, if we want to understand the whole…

2

Reverse P/Invoke and exception

P/Invoke is managed code executing a native function pointer. And Reverse P/Invoke is native code executing a managed delegate as a function pointer, mostly as a callback. When the native code executes the managed delegate function pointer, the call really calls into a CLR thunk. The thunk will do an AppDomain transition to the correct…

3

Assembly Loading and Authorization

CLR does not do anything special regarding authorization during assembly loading. It will try to access the file under the current user. However, if an assembly is already loaded, next time when the assembly is requested, CLR will return the assembly from the cache without hitting the file. When the application impersonates a user, things…

0

Loading CLR DAC dll from a different path

From .Net framework 2.0, CLR creates a debugger helper dll mscordacwks.dll. The dll is used by Windows Debugger to enumerate CLR data structures. Mscordacwks.dll is part of .Net framework redist. C:\Windows\Microsoft.NET\Framework\v2.0.50727>dir mscordacwks.dll  Volume in drive C is Vista  Volume Serial Number is C84C-2424  Directory of C:\Windows\Microsoft.NET\Framework\v2.0.50727 07/10/2007  04:38 PM           812,544 mscordacwks.dll                1 File(s)        812,544…

2

The Unusual Ref/Def Mismatch FileLoadException

One of my colleagues has experienced a very strange Ref/Def Mismatch FileLoadException (The located assembly’s manifest definition does not match the assembly reference). After a long investigation, we finally track down the cause. To explain the problem, we have to understand the sequence of assembly loading and the interaction between fusion and CLR. The  key…

1

The sequence of interactions between CLR loader and fusion during Assembly.Load

The following describes roughly the sequence of interactions between CLR loader and fusion during Assembly.Load() in .Net framework 2.0. 1. User calls Assembly.Load. 2. Loader pass the assembly reference to fusion. 3. Fusion checks to see if the assembly has already loaded. If it is, the assembly is returned. 4. If not, fusion probes the…

3

Lock(object) and ThreadAbortException

We have experience some weird deadlock using managed code. We have a class with some shared resources. To protect the shared resources, we create a synchronization object, and use Lock(object) prior to access the shared resources. There is no nested lock so in theory we should never have deadlock. However, for some reason, one of the…

2

Don’t catch all exceptions

One of the best practices on exception is don’t catch all exceptions. There are many reasons why this is a best practice. For example, You want to look at the application state when the exception is thrown so that you can understand exactly why the exception is thrown. The exact state is often lost when…

3