I wrote a small profiler for .NET applications. It uses the ICorProfilerCallback2
interface.
The profiler attaches and works well for .NET 2.0 application but doesn't work for .NET >2.0 (3.0, 3.5, 4.0). When I start an exe compiled with .NET 4.0 nothing happens, however for .NET 2.0 the profiler starts. I'm setting the following variables before running a managed exe
@Echo off
set Cor_Enable_Profiling=0x1
set COR_PROFILER={67D8965A-8686-2639-9C24-E1F7D13EE105}
set COR_PROFILER_DLL=e:\Debug\Profiler.dll
set COR_PROFILER_PATH=e:\Debug\Profiler.dll
Any idea why this might happen? It doe开发者_如何学运维sn't even get in DllMain
Timotei,
The problem you discuss is likely covered in David Broman's post:
David Broman's CLR Profiling API Blog: Run your V2 profiler binary on CLR V4
For the CLR V4 runtime you should see some useful information in the Event Log (view with Event Viewer) describing why the profiler failed to load.
If you don't want to use the COMPLUS_ProfAPI_ProfilerCompatibilitySetting
setting discussed in the blog you could also support the ICorProfilerCallback3
interface to add support for the V4 runtime.
With CLR V4 you may also have to consider side-by-side scenarios, where both the V2 and V4 runtimes are loaded into a single executable. For more information refer to David's other post titled 'Profilers, in-process side-by-side CLR instances, and a free test harness' (sadly I can't post a link to it as well due to Spam Prevention).
精彩评论