2

The question has been asked many times without an answer for me. This version is with a C# .NET CONSOLE application and happens with the default C# program.

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

From Visual Studio Community 2017 - Create a new C# Console Application with all the defaults and build either the Release or Debug config. If you run it from within the VS environment, or even from the command prompt after completion the .exe will remain locked and owned by 'System' w/PID of 4.

Attempt to rebuild it. - the .exe is locked and can't be overwritten producing the retry count error.

How to create the default console app: File -> New Project -> Templates -> Visual C# -> Windows Classic Desktop -> Console App (.NET Framework) [The .NET version doesn't seem to matter]

Using process explorer to search for the file name shows that it is being access by system w/PID of 4. Lockhunter suggests a reboot.

Sometimes closing VS releases it. I've also tried using x86 in debug and x64 in release - in one case the .exe was unlocked. Unchecking debug/trace made little / no difference. Deleting the .pdb doesn't seem to matter.

In this simple example, after a minute or so the .exe may be unlocked from system PID 4, but in my actual project it takes 15 mins. I'm using 5 build configs to avoid the problem - (I'm attempting to interface w/hardware-software that is poorly documented.)

I'm running Win 7 Pro Sp 1 x64, with Win Defender stopped and anti-virus UN-installed. Experiments where done after a clean reboot before starting other applications - although Vmware service, OnTime RTOS service, and many other application services are running.

pathfinder
  • 106
  • 1
  • 8
  • right click on the exe and select open as Admin.. this should fix your problem.. Visual Studio exe that is – MethodMan Apr 27 '17 at 16:31
  • Running VS both as user and admin. Problem also isn't just VS2017 - same thing in 2015 community which is why I upgraded. Usually run VS as admin to (re)start the RTOS and access shared memory. – pathfinder Apr 27 '17 at 17:24
  • do you have something in your code that's not freeing memory or releasing when shutting down the application? you can check the Task Manager to see if the process is still in memory after shutting down.. and that could be what the issue is.. but can't tell with what little code you have posted, which would have no bearing on the issue that you are describing.. – MethodMan Apr 27 '17 at 17:31
  • This example is the default program created by VS. I got here by subsequently deleting everything thing in my program (starting w/DLLs) - but when there was nothing left it still happened. So I created 6 new console apps and voila - its still locked. If you follow the directions does it happen w/you? Possibly there is something about my system that is the cause. – pathfinder Apr 27 '17 at 17:36
  • based on what you are doing.. it's really hard to see what's going on without seeing the exact thing you are doing.. I don't experience this issue except for when the program is locked in use ...can you create a new application and test it.. have you tried doing CLEAN and then rebuild..? – MethodMan Apr 27 '17 at 17:45
  • When I create a NEW application is the example I'm giving. – pathfinder Apr 27 '17 at 18:17
  • So - it appears to be system specific - as I have another Win7x64 that doesn't have the problem - at least in the simple case. – pathfinder Apr 27 '17 at 18:19
  • what do you have the project set to for running / executing the application - program `AnyCpu , x86, or x64`? – MethodMan Apr 27 '17 at 18:20
  • 1
    You are going to need to diagnose this on your own. Visual Studio by itself would not have this problem, even when running as a Standard user, without admin rights. You must have some other process that is watching for files and opening them. Things like search indexers and anti-malware software might do this, as would poorly-written media-cataloging software. Your question is not very useful to the Stack Overflow community, because even if you track down the culprit, the next time someone else has this problem, it'll almost certainly be something else. – Peter Duniho Apr 27 '17 at 18:21
  • Here is a Xamarin bug report you can follow https://bugzilla.xamarin.com/show_bug.cgi?id=56275 – Joshua Poling May 13 '17 at 13:12
  • 1
    @JoshuaPoling - interesting - I gave up on the console app because of the problem (although it happens less often in other projects) but will try an VS update as suggested in the xamarin bug report thread. Thank you. – pathfinder Sep 03 '17 at 16:49
  • Take a look on this question https://stackoverflow.com/questions/18102859/visual-studio-could-not-copy-during-build – electrodrel Nov 01 '17 at 17:08
  • @electrodrel - Its good to have this link for the next person that finds my question. Unfortunately, the accepted answer didn't work for me. – pathfinder Nov 14 '17 at 20:43
  • Once upon a time Visual Studio had the debuggin Hosting Process which tended to avoid problems such as this. Sadly it has been removed in VS2017 –  Dec 12 '17 at 07:39

0 Answers0