Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2013: "VSP2340: Environment variables were not properly set" even when running from IDE

I am profiling a C# program from Visual Studio 2013. I go to Analyze -> Performance and Diagnostics to start the wizard. It gives me a choice of profiling method. If I choose the default, CPU sampling, then profiling works and I can see the results. However if I choose the third option, .NET memory allocation, then after my application has finished I see empty results and this error in the Visual Studio output window:

VSP2340: Environment variables were not properly set during profiling run and managed
symbols may not resolve.  Please use vsperfclrenv before profiling

All the documentation I've seen online suggests that vsperfclrenv is for use with the stand-alone profiler and is not needed when you run the profiler directly from Visual Studio. However, just to be on the safe side I tried setting the necessary environment variables from a command prompt window and then running the IDE directly from that window, so it picks up the environment:

C:
cd "\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Performance Tools\x64"
vsperfclrenv /samplegclife /tracegclife /globalsamplegclife /globaltracegclife
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe"

Then I went to the performance wizard inside Visual Studio as before. But the result is the same; I still see the VSP2340 on trying to analyse the results. What am I doing wrong?

I note that the wizard has four kinds of profiling to choose: CPU sampling, instrumentation, memory allocation, and resource contention. That doesn't quite match with the options offered by vsperfclrenv, which talks about only sampling and trace profiling (with application vs service variants of each; my program is an application not a service, but I enabled all the options just to be sure).

Could it be there is some additional environment variable needed for memory allocation profiling? Or is the Visual Studio message about vsperfclrenv misleading?

like image 862
Ed Avis Avatar asked Oct 03 '14 13:10

Ed Avis


1 Answers

This may be related to administrative privileges. In my case, I know of two workarounds:

  1. Run Visual Studio as a user with real administrator privileges.
  2. Use the [Start -> Microsoft Visual Studio 2012 -> Visual Studio Tools -> ] Developer Command Prompt for VS2012 -> Run as administrator. In command prompt, vsperfclrenv /samplegclife. Window title changes from Administrator: Developer Command Prompt for VS2012 to Administrator: VSPerf Sampling Attaching and Allocation Profiling with objects lifetime 'ON'. Then "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe".

The second approach looks just what the original poster did, except that instead of an ordinary cmd.exe window, I used Run as administrator with the Developer Command Prompt. For me, when I do not run as administrator, I get the VSP2340 error.

I have been experiencing very similar symptoms with a slightly different environment: Windows 7, as a normal user (not in the local Administrators group), starting Visual Studio 2012 from the Start Menu, with Avecto Defendpoint to grant elevated privileges to the Visual Studio executable, CPU profiling produced normal results but .NET memory allocation sampling results were blank. Output window said:

Profiling started.
Profiling process ID #### (xxxx).
Process ID #### has exited.
Data written to C:\path\to\solution\xxxxyymmdd.vsp.
Profiling finished.
VSP2340: Environment variables were not properly set during profiling run and 
    managed symbols may not resolve. Please use vsperfclrenv before profiling.
Profiling complete.

For CPU profiling runs, instead of VSP2340, I get a long listing of Loaded symbols for [full/path/to/dll]

like image 50
Richard C Yeh Avatar answered Oct 26 '22 15:10

Richard C Yeh