Using CLR Profiler 2.0 with XNA 4.0

Using CLR Profiler 2.0 with XNA 4.0

By default (at least on my computer, running Windows 7), CLR Profiler 2 won’t work with new XNA apps since they utilize the new .NET framework. It looks like it’s working when you try it, but when it shows the final statistics window it’s empty. Fortunately, it’s possible to enable support using the new profiler compatibility settings functionality, which for this case involves simply setting the COMPLUS_ProfAPI_ProfilerCompatibilitySetting environment variable before running CLR Profiler.

Here’s what I did:

Create a batch file called start_clr_profiler.bat with this content, save it in Documents or wherever:

cd "program files (x86)clrprofilerbinariesx86
set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler

It goes without saying that you’ll need to change the drive and path to where you have CLR Profiler installed.

Once you have this file, create a shortcut to it on your desktop. Right click on the shortcut, select Properties, click the Advanced button and check “Run as Administrator”. Click OK a couple of times, and you’re good to go. Just start the profiler with the batch file and the environment variable will be set, and the profiling magic will happen.

You could also set that environment variable at the user or machine level so it’s set all the time, but I don’t know what ramifications that has so prefer setting it just when needed. Happy garbage collecting!

9 thoughts on “Using CLR Profiler 2.0 with XNA 4.0


    been desperately needing a free CLR profiler for a large XNA 4.0 project I’ve been working on. it’s been heart wrenching to find no solutions on google or the xna community forums. thanks for this =]

  2. Thanks, I got CLR Profiler 2.0 to work with XNA 4.0 in this manner. However, it only worked for the x86 version, not the 64-bit version, which is strange.

    Also, I’d like to know why CLR Profiler 4.0 doesn’t work with XNA 4.0 as-is. Do you have any suggestions on how to make it work? It shouldn’t require any help.


    1. One thing I noticed is that I have to have Allocations and/or Calls checked before I start my app. If I check them after the app starts (if I’m trying to just profile a certain part of the app for example) then I never get any data. So I always make sure those are checked, leave Profiling Active unchecked, start the app, navigate to where I want, then check Profiling Active. Other than that, as long as I run it as administrator, and set the working directory in File/Set Parameters everything seems to work pretty well with it.

Comments are closed.

Comments are closed.