How to indentify a managed exe or dll.

What's the best way to identify a managed exe or dll so one knows what debugging interface to use.

Thanks.

- Dan.

[118 byte] By [DanBaumbach] at [2008-2-23]
# 1

In Whidbey (v2.0), we added some new APIs for this:
mscoree!GetVersionFromProcess - tells you if a currently running app has the CLR loaded, and if so, gets the version string in the version of another process
mscoree!CreateDebuggingInterfaceFromVersion - creates an ICorDebug for a given version string. See here for usage details.

pre-whidbey, there is also
mscoree!GetRequestedRuntimeVersion - predict version of CLR that an exe will load. This is just a prediction and so may not be accurate.

MikeStall-MSFT at 2007-9-4 > top of Msdn Tech,.NET Development,Building Development and Diagnostic Tools for .Net...
# 2
GetVersionFromProcess() will return E_INVALIDARG for a running process thats not managed code. GetRequestedRuntimeVersion() returns S_OK but the version string is empty when a you call it with a not running non managed code exe. If I load an exe into Visual Studio and press F5 is that how it determines what debugging interface to use?

- Dan.

DanBaumbach at 2007-9-4 > top of Msdn Tech,.NET Development,Building Development and Diagnostic Tools for .Net...
# 3

If an app has not yet loaded the runtime, you can't 100% predict which CLR version it will load. Imagine an unmanaged app that pops up a dialog asking the user for which runtime to load and then it calls CorBindToRuntime on the fly.

GetVersionFromProcess() tells you if the app has already loaded the runtime and which version if so. As you note, it fails to communicate that no runtime is loaded. This is generally sufficient in the attach case, particularly when the app is already running managd code.

GetRequestedRuntimeVersion() is called on a exe file, not on a running process, so the there is no managed code yet. However, if the file is a compiled from C#, GetRequestedRuntimeVersion() should accurately predict. If the file is a pure unmanaged exe (without CorHeaders in the image), then this API won't help either. However, adding a config file next to the app should make this API work right.

These are the APIs that VS / MDbg use. Check out debugger.cs in the MDbg sample for usage patterns of these APIs.

MikeStall-MSFT at 2007-9-4 > top of Msdn Tech,.NET Development,Building Development and Diagnostic Tools for .Net...

.NET Development

Site Classified