0

I have a CLR profiler that I have written which injects code into methods at JIT time. The code I inject depends on .NET 3.5+. How can I detect the version of the .NET Framework that is available at profiler initialization time (ICorProfilerCallback::Initialize)?

Ideally, if they don't have .NET 3.5+ installed, I would like to simply not have my profiler loaded which means returning CORPROF_E_PROFILER_CANCEL_ACTIVATION from Initialize. If I don't detect the version until later (such as on module load) then my profiling flags will be set and certain CLR optimizations will be disabled which is undesirable since the profiler won't actually work.

3
  • Covered in this article, ICLRMetaHost::EnumerateLoadedRuntimes() tells you which CLRs are loaded. Commented Apr 30, 2014 at 21:12
  • I believe that ICLRMetaHost is only available on CLR 4. Also, I need to know what the runtime that is currently executing is, not what is installed on the system. The CLR Hosting Interfaces may work (I didn't know about them), though I am uncertain about what CLR Hosting interfaces will be accessible at profiler initialization time since the CLR hasn't fully loaded yet. Commented Apr 30, 2014 at 21:17
  • ICLRMetaHost was introduced with CLR 4, but can still detect earlier versions (if you don't mind the extra dependency). It probably wont help though as .NET 3.5 uses version 2 of the CLR. If you don't mind dropping support for 3.5 and demanding .NET 4, you could use ICorProfilerInfo3::GetRuntimeInformation(). Commented Feb 10, 2015 at 8:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.