STA Objects and the Finalizer Thread: Tale of a Deadlock

June 30, 2010

Here’s a non-trivial deadlock that manifests from using a non-pumping wait API and a finalizer. It is another example of why finalizers are a dangerous cleanup mechanism and why you should avoid them at all costs. Let’s say that you have an STA COM object called NativeComObject that your managed application is using, and you wrap the COM object with a class called FinalizableResource. This latter class has a finalizer that cleans up resources associated with the COM object by calling a cleanup method on it, or even by deterministically releasing the object with Marshal.FinalReleaseComObject. Note that...
no comments

MDA: Callback On Garbage Collected Delegate

June 11, 2010

One day I’m going to write a long, detailed post about an incredible tool called Managed Debugging Assistants (MDAs). But today is not that day. Instead, I would like to ignite your interest in MDAs by showing you how they immediately make obvious a non-trivial debugging scenario. Oren writes: if you run on a background thread and continue to do additional operations it will crash, sometimes with a null reference exception, sometimes with attempt to write to protected memory, etc. There is a very subtle bug here,...
no comments

Assembly.ReflectionOnlyLoad Ignores Assembly Binding Redirects

June 9, 2010

This is a short post to make you aware of the fact that Assembly.ReflectionOnlyLoad does not honor assembly binding redirects. Assembly binding redirection allows you to specify at the machine- or application-level that if an application attempts to load a certain version of an assembly, it should load another version instead. For example, I don’t have .NET 1.0 installed on my system, but .NET 1.0 applications can run successfully because there are binding redirects in place. For example, when an application requests the 1.0.3300.0 System.Data.dll assembly, a binding redirect will give it the version. This is...
no comments

My New Desktop

After almost three years using the same desktop PC, I finally switched the whole package. With Alon’s help and recommendations I managed to come up with this spec: Intel i7 860 processor @ 2.80 GHz, 8 MB cache Gigabyte P55A-UD4 board (SATA 6 Gb/s and USB 3.0 ports) OCZ Gold DDR3 1333 MHz 8 GB memory Intel 80 GB SSD X25-M ATI Radeon HD 5850 graphics card with 1 GB DDR5 memory and DirectX 11 support ...

Viewing Persisted Workflow State

June 4, 2010

A few weeks ago at work I was toying around with implementing a viewer for persisted workflow instances (with WF 3.5). While there is a Microsoft sample (Workflow Monitor) that displays tracking information recorded for a workflow instance accompanied by a visual designer, there is no API or tool to view the state of a persisted workflow—the property values and object references that are serialized to the workflow persistence store. It’s always possible to write a custom persistence service that will serialize workflows in any way you deem fit, but I decided to do something simpler. I wrote...
one comment