Sample Reflection.Emit code for using exception filters from C#

In this post, I mentioned that one way to use exception filters from C# code is to generate them with Reflection.Emit.  Personally I usually prefer static compilation (even post-build assembly merging or rewriting) – there’s really nothing here that necessitates dynamic code generation, but I can understand the desire to avoid complicating the build process. …

0

Quickly seeing where an exception may land in the debugger

A co-worker asked me recently how he could predict where an exception that was about to be thrown would land while debugging a managed application.  The real answer to this question is “you can’t – step into the throw and see”.  The EH system in the CLR has lots of complicated algorithms for determining this,…

0

New interviews with my CLR team members up on Channel9

There are a bunch of great new CLR v4-related video interviews up on Channel9.  In particular: Jon, Thomas and Dave from my team (CLR diagnostics) discuss the advancements in debugging and profiling APIs in v4 Simon and I discuss in-process SxS (ability to have multiple CLRs loaded in the same process).  You may have noticed the…

0

AnyCPU Exes are usually more trouble than they’re worth

Over the past few months I’ve had some interesting debates with folks here (and some customers) about the cost/benefit trade-off of “AnyCPU” (architecture-neutral) managed EXEs.  I think we’ve converged on a consensus that most of the time they’re not what you want and so shouldn’t be the default in Visual Studio.  I suspect this topic may…

18

Getting good dumps when an exception is thrown

Often, when an unexpected exception occurs in production code, applications want to generate (and potentially report) some sort of diagnostics information.  Sometimes people just want to write to a log file (and perhaps pop some error dialog) for support purposes, but more sophisticated applications will want to have a mechanism to save a minidump of…

5

CLR 4.0 advancements in diagnostics

We announced at PDC today that we’re making some significant advances in diagnostics tool support for CLR v4!  In particular, we’ve been investing heavily in improving our support for production diagnostics scenarios over the past couple years.  I’m excited that we’re finally able to start talking about it! Here’s a quick list of some of the…

16

Func-eval can fail while stopped in a non-optimized managed method that pushes more than 256 argument bytes

In this blog entry, Mike describes that func-eval will fail when not a GC-safe point.  In VS this results in the error “Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code is optimized”.  Typically non-optimized (debuggable) managed code is compiled as “fully-interruptible” which means…

1

Invoking a virtual method non-virtually

Method calls using the C# ‘base’ keyword get compiled to an IL ‘call’ instruction, rather than the ‘callvirt’ that is normally used. This is the one case in C# where a virtual method can be invoked without virtual dispatch. The CLR allows it to be used generally for non-virtual calls, but it’s unverifiable in other…

3

Customizing PDB lookup for source information in StackTrace

The System.Diagnostics.StackTrace class in .NET can be used to generate a textual representation of the current callstack.  This is used, for example, by Exception.ToString(). If requested by the caller, StackTrace can include source file locations (file names and line numbers, etc.) for each frame whose module has a PDB file available to the CLR.  PDB…

4

Code Sample – StackTrace with manual Symbol lookup

// Sample to demonstrate creating a stack trace with source location information while controlling // how PDB files are located. // Written by Rick Byers – http://blogs.msdn.com/rmbyers // 6/21/2007 – Initial version using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.SymbolStore; using System.Runtime.InteropServices; using System.Reflection; // Use MDbg’s managed wrappers over the corysm.idl (diasymreader.dll) COM APIs…

3