How to indentify a managed exe or dll.
Thanks.
- Dan.
Thanks.
- Dan.
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.
- Dan.
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.