Is there any where to get the CLR ID at runtime for the current application? I am monitoring my system using Performance Monitors and the name used for the instance is:
ApplicationName.exe_p4952_r15_ad1
I can get all other parameters programmatically but not the r15 which is the runtime ID of the common language runtime (instance) that executes your code. I noticed it is always 15, but it is best to get it dynamically to avoid complications.
You can get the whole “suffix”, i.e. the part after
Application.exeusing the same infrastructure that the .NET framework (e.g. the peformance counters) does.There is the method System.Runtime.Versioning.VersioningHelper.MakeVersionSafeName, which can do that. Note that the method is described as being “Infrastructure” and “This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.”, but nevertheless is public. I don’t think there is any “better supported” way to get the information you want. At least it is more robust and resilient to future changes, then reverse engineering the information based on documentation.
This returns
_p4472_r16_ad1, for example.Of course, you could also directly pass the basename of the performance counter to directly get the full name. The usage of the empty string above is only a trick to just get the “suffix”.
The class
VersioningHelpersalso has the private methodGetRuntimeId(), but given the above, I don’t think it is neccessary to use reflection on that achieve what you need.