How to stop the Visual Studio debugger starting my process in a job object? - visual-studio

When I start my process from Visual Studio, it is always created inside a job object. I would like to know how to turn this behaviour off. Any ideas?
I expect that it is created in a job object to be debugged. I want to place my program in a different job object.
It's not the hosting process. I'm talking about a Job Object. This is an unmanaged C++ application.

This happens when devenv.exe or VSLauncher.exe run in compatibility mode. The Program Compatibility Assistant (PCA) attaches a job object to the Visual Studio process, and every child process inherits it. Check if the job name (as reported by Process Explorer) starts with PCA. If so, PCA can be disabled as described in the link.
You can globally disable PCA using Run -> gpedit.msc -> Administrative Templates\Windows Components\Application Compatibility -> Turn off Program Compatibility Assistant -> Enable.
You can disable PCA for specific executables by adding a registry entry. For Windows 7, the appropriate registry key is HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant. In regedit, right-click that key, select New -> Multi-String Value, name it ExecutablesToExclude. Set the value to the full path of denenv.exe and VSLauncher.exe, on separate lines and without quotes. For me, these were:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe
C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\VSLauncher.exe
A related issue, on Windows 7, is that executables you build in Visual Studio and run from Explorer (not Visual Studio or the command line) may run in compatibility mode, and again get job objects wrapped around them. To prevent this, your executable needs a manifest that declares compatibility with Windows 7, using the new Application Manifest Compability section. The link gives an example of a Windows 7 compatible manifest. The default manifest provided by Visual Studio 2010 does not include this Compatibility section.

I'm not aware of any ways to control this aspect of processes spawned for debugging by VS.NET. But there's a workaround, which is applicable to any situation in which VS.NET can't or doesn't start your process in the exact way you want:
Start your process (possibly using a wrapper EXE that runs as part of the post-build event), then attach to the newly started process using Tools/Attach to Process. If you break into the debugger as part of your startup code, this won't even be required (and you can also debug startup issues...).

I can't reproduce what you're seeing. I've created an unmanaged C++ application in both VS 2005 and VS 2008 and I have no problems associating that process to a new job object when starting the process in VS.
Are you sure the debugger is doing this?

Related

PDB remains open after debugging (Windows 10, Visual Studio)

Our previous development systems used Windows XP and Windows 7. Debugging C++ DLLs from Visual Studio worked great.
A recent move to Windows 10 has resulted in an annoying problem. We can debug once (using F5), but the 2nd time results in a linker error:
MyProg fatal error LNK1201: error writing to program database 'MyProg.pdb'
Trying to delete the .pdb manually in Explorer while Visual Studio is still open results in the error:
The action can't be completed because the file is open in devenv.exe
It doesn't matter whether you hit a breakpoint or not. Just start debugging once results in the problem. Re-starting Visual Studio resolves the issue (in the sense that you can debug once, but then you get the problem again).
If relevant:
x86 Visual Studio 2003.NET
targeting another x86 application
x64 Windows 10 Pro v1803
After hunting around for several hours some related, but unanswered, questions were found. Following suggestions in this MSDN article, along with some debugging of my own, this solution works:
Download FreePDB, a script written by MSDN user Toni76 (thanks Toni!)
Copy this script to a local folder (say C:\Apps\FreeDPB)
Download the latest version of SysInternals tool Handle (currently v4.21)
Copy handle.exe to C:\Apps\FreeDPB
NB! From the command line, run handle /? once. This is to agree the EULA. The script will not work if you skip this step!
Open Visual Studio, then Project > Properties > Build Events > Pre-Build Event
Set Command Line to C:\Apps\FreeDPB\freepdb $(ProjectName)
Set Description to Delete lock on PDB
...and now you don't need to restart Visual Studio to debug a 2nd time!
From comments, this works with multiple versions of Visual Studio on multiple versions of Windows.
Update
A more radical solution is described here which involves replacing a core Visual Studio DLL (NatDbgDE.dll). This solution only works for Visual Studio 2003 SP1, though.
In my case it was due to "Process Explorer" program, which was open alongside with my Visual Studio(I used it to check some properties of the exe I've created). After closing it problem solved.

Why do my Visual Studio solution executables need to run as Administrator?

I used Visual Studio 2010 on Windows 7 for a while and never had this problem, but with the current VS solution whenever I run the executable created from any Fortran project (both debug and release) I get the message
This task requires this application to have elevated permissions.
and I'm asked to restart Visual Studio as Administrator.
I don't want this, I want to create executables that run not as administrator unless right-clicked => run as administrator. That has always been the case for all my solutions except this one and I cannot figure out what I did different.
How can I change this behavior?
In your project's linker properties there is the manifest file group of options.
Inspect the value of
UAK Execution Level
Probably it is set as
requireAdministrator
You should change it to
asInvoker

VS 2008 Attach to process disabled

I have used the attach to process feature of visual studio a number of times. However now when i try to attach to a process (dll) the Attach button is disabled. However if i select any other process except the managed one the Attach button is enabled! My problem is closely related to the problem described at the link below
VS attaching to process disabled
A picture of the dialog is attached.
This is almost certainly because there is already another debugger attached to the process - probably the currently running instance of Visual Studio but it may be another instance of Visual Studio, or another debugger entirely (such as WinDbg or a remote debugging session).
Check the "Processes" window (usually found under Debug -> Windows -> Processes) to see what processes Visual Studio is debugging.
Found the solution to the problem
How to step into C/C++ DLL from C# application while debugging
http://msdn.microsoft.com/en-us/library/605a12zt%28v=VS.90%29.aspx

How to configure WinDbg to be one of the optional debuggers when application hit a user defined break point?

when an application on my machine encounter a user defined break point it windows opens a dialog that let me choose a debugger to attach to the process.
Currently it offers me to choose one of the two versions of visual studio that installed on my machine (2008 or 2010) I want to add to the options WinDbg.
Is it possible?
There used to be (in VS2005, I think) an undocument way to do this, but it doesn't seem to work in VS2008 or 2010. You used to be able to run vs7jit.exe /RegisterOld "C:\debuggers\windbg.exe" "Windbg". I can't find how to add it to the list in VS2008 or VS2010.
However, you can set the default debugger to be WinDbg. This would replace the VSJitDebugger.exe that is the default (which is what gives you the two Visual Studio versions to choose from).
For the .Net Framework 4, you can set this in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug key under the Debugger value. Just put in the path to WinDbg. For versions of the Framework previous to 4, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework and the value name is DbgManagedDebugger.
Here's some additional information on launching debuggers: http://blogs.msdn.com/shawnfa/archive/2004/07/15/184490.aspx

Visual Studio 2005 - can not open form on designer

My team developed a GUI application on Visual Studio 2005, managed C++. Since some deliveries it is not possible to open the form in the designer, even if the source code and the project settings have not been changed. The designer reports this error:
Exception of type 'System.OutOfMemoryException' was thrown.
at Microsoft.VisualStudio.Design.VSDynamicTypeService.ShadowCopyAssembly(String fileName)
at Microsoft.VisualStudio.Design.VSDynamicTypeService.CreateDynamicAssembly(String codeBase)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_Assembly()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.Search(String fullName, String typeName, Boolean ignoreTypeCase, Assembly& assembly, String description)
...
We successfully recompiled the project but we still encounter this problem.
Any idea?
This is how I used to debug these issues, Start a second instance of visual studio, load your project and attach to the first instance which also has the project loaded. Now set a breakpoint in the constructor and Page Load events and also any custom paint events that you may have in the form in the second instance and try to open the designer in the first instance, the breakpoints should get hit and you should be able to see what's going on.
I suspect that you have a Design Mode error where an infinite loop (or recursive control creation) occurs on the concerned Form.
One thing that helped me in these kinds of error on Windows Forms would be the following:
Open your Visual Studio 2005 solution for your GUI application. Don't open your form yet
Open another instance of Visual Studio 2005
In the second instance, Attach (Debug -> Attach to Process) the first instance of devenv.exe to the debugger. Make sure exceptions (Debug -> Exceptions) have all exceptions checkboxes under "Thrown" checked.
Now go to your first VS2005 instance and open the form. The second VS2005 instance will stop at the line where the error occurs.
This is a long shot, but try closing and opening the designer several times in a row. I have had the same kinds of problems with the C# Windows Forms designer (VS2005) : the form usually ended up opening correctly (after 5 tries, quite consistently).
I've run into the same issue intermittently when working with a large multi-project solution, or a project with an exceedingly large and complicated windows form.
I was able to solve the problem by enabling Visual Studio to use more than 2GB of memory. Here's the process...
(note: this assumes XP and Visual Studio 2005 - Vista and/or VS2008 will require slight changes)
Edit Boot.ini
Right-click My Computer, properties, Advanced tab. Under Startup and Recovery click Settings. Click the Edit button, and add the /3GB switch to the end of the [operating systems] line:
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect /3GB
Make Visual Studio "Large Address Aware"
Run a Visual Studio Command Prompt, and change to the IDE directory:
cd %ProgramFiles%\Microsoft Visual Studio 8\Common7\IDE
Use the microsoft tool editbin to modify devenv.exe:
editbin /LARGEADDRESSAWARE devenv.exe
Now reboot, and you're done!

Resources