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.

valiano
  • 16,433
  • 7
  • 64
  • 79
Micah Zoltu
  • 6,764
  • 5
  • 44
  • 72
  • Covered in [this article](http://msdn.microsoft.com/en-us/library/dd997942%28v=vs.110%29.aspx), ICLRMetaHost::EnumerateLoadedRuntimes() tells you which CLRs are loaded. – Hans Passant Apr 30 '14 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. – Micah Zoltu Apr 30 '14 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(). – Brian Reichle Feb 10 '15 at 08:33

0 Answers0