20

I've experienced this with every version of Visual Studio starting from 2012 (2012, 2013, 2015 Preview), on multiple computers and multiple projects, but I haven't figured out how to fix it:

Whenever I'm debugging a 64-bit(?) C++ console program, after a few minutes and seemingly completely randomly (when I'm not clicking or typing anything), the console window for the program spontaneously closes and I can no longer debug or step through the program with Visual Studio. When I press Stop and attempt to restart debugging, I usually get ERROR_NETWORK_UNREACHABLE:

// MessageId: ERROR_NETWORK_UNREACHABLE
// MessageText:
// The network location cannot be reached. For information about network troubleshooting, see Windows Help.
#define ERROR_NETWORK_UNREACHABLE        1231L

If I try to attach to the process manually I get the error:

Unable to attach to the process.

The only fix I've found for this is to restart Visual Studio. I can't find any other way to fix it, and I've tried running Process Monitor but haven't found anything.

What causes this problem and how can I fix it?


(?) Upon further checking it seems that this only happens in 64-bit mode, but I'm not 100% sure.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
user541686
  • 205,094
  • 128
  • 528
  • 886
  • Are you sure you're debugging only the one program? If you right-click on the top-level Solution node in the Solution Explorer and select "Set Startup Projects," is "Multiple startup projects" selected? – Dan Korn Jan 10 '15 at 00:31
  • `The network location cannot be reached.; `? Just that? No location name? How does the message look like? Can you take a screenshot? Do you work with some UNC shares? Is there any chance that your VS or Solution is using a UNC share as an intermediate directory for building (bin,obj folders?) due to custom setup? have you tried running them separately without VS and then attaching the debug session to them? – quetzalcoatl Jan 10 '15 at 01:53
  • @DanKorn: Yup it's just one program... in fact there's no other project in the solution. – user541686 Jan 10 '15 at 06:54
  • @quetzalcoatl: Nope no location name... in fact there is network involved anywhere at all, everything is on a local drive. See the screenshots I just added. – user541686 Jan 10 '15 at 06:56
  • Just to make sure, you created a new project from scratch and that exhibits the same behaviour, right? I'd also check the trace window for messages that don't belong there like DLLs that shouldn't be loaded. I'm afraid the reason is not in your code but rather in some other code running on your machine. – Ulrich Eckhardt Jan 10 '15 at 08:44
  • @UlrichEckhardt: Yes, it happens on a new project I created from scratch, but with the scratch program I created I just noticed it only happens when debugging 64-bit outputs... hmm. – user541686 Jan 10 '15 at 08:58
  • @UlrichEckhardt: On a second thought, the error I got with that project I just created from scratch was a bit different, I'm having trouble reproducing these exactly... they're kinda spontaneous, I'll have to get back to you. – user541686 Jan 10 '15 at 09:19
  • These kinds of bugs are highly annoying. Anyhow, one more idea that could cause it: Swapping. If your system swaps to a network location after some time, I could imagine things happening. Good luck hunting this down! – Ulrich Eckhardt Jan 10 '15 at 09:24
  • @UlrichEckhardt: Haha, I've actually disabled my pagefile entirely, so that's not the issue either. And like I said, there isn't a network involved to begin with -- I don't know why the error says network location, but there are no network files involved anywhere. (Btw, I don't think swap files can be on network drives...?) – user541686 Jan 10 '15 at 09:26
  • 2
    @UlrichEckhardt: Okay, so here's exactly what happened in one instance: I got the network error when debugging an x64 Release build. I clicked OK on it, then closed the solution (keeping the IDE open) and re-opened a completely different solution. When I tried debugging that one in x64 mode, I got back the error *"Unable to start program [program path here]."* Then I opened the original solution again and tried running it again, and this time I got back this latter error (no mention of networks). So the error message is unrelated to the project and solution, it seems to relate to the debugger. – user541686 Jan 10 '15 at 10:15
  • I completely overlooked it - it happens on **multiple computers**? I can hardly imagine what could it be. That'd suggest that either it's some bug in the IDE itself (why noone noticed it before?), or in the way you have configured your solution settings which you copy around. Have you tried a plain fresh installation of VS2xxx, no plugins, on a new machine (virtual one should be OK too), and trying to debug a completely empty project generated by VS project templates? If that fails too, then I'd check the OS or some sniffer.. Maybe couldn't connect to domain to check if you have permissions? – quetzalcoatl Jan 10 '15 at 13:21
  • 1
    However, net-sniffer may show nothing.. In terms of windows errors, a "network location" can sometimes refer to ie.e a namedpipe. – quetzalcoatl Jan 10 '15 at 13:23
  • That reminds me-if you are using NTFS filesystem,then some messages about disk/filesystem failures also seem network'ish. I seen some errors that looked like network-related for cases when files were locked by some internal/kernel'ish windows service, or when there was some error in the directory structure. Funny errors also occur when **absolute file paths** of the items in solution start to touch the MAX_PATH limit. It happens to me often when project is "deep", but these errors I don't remember to look like network-related. Also, FS/Disk failures wouldn't be consistent between machines :| – quetzalcoatl Jan 10 '15 at 13:26
  • Another thing, but that would be hyper-strange. With MachinDebugManager and RemoteDbugging installed everywhere, the debugger can also connect to remotes and debug processes on remote machines. Maybe, for some very strange reason, the VS IDE tries to do that. Connection is set up either by IP or "ComputerName" (machine name in a workgroup). So, then, if the nameservice (DNS?) check failed to resolve the name, I could imagine to get such errors. But I can't think of why your IDE would try to connect to localhost by RemoteDebugging instead of just doing it locally. Incredible. – quetzalcoatl Jan 10 '15 at 13:31
  • 1
    @quetzalcoatl: Yeah I don't know. It certainly happens on multiple machines, and the only things that were common between the machines were the facts that (1) at some point I tried to run the same project on both of them, (2) my settings are similar for the two (but not migrated), and (3) both have Windows 8.1. It may be that I'm forgetting something but I don't know what it could be. I feel like it's a bug in MSVSMon but I'm baffled why no one else seems to be running into it. – user541686 Jan 10 '15 at 19:11
  • 2
    @Mehrdad well guess what, you're not the only one, this error is driving me crazy, I get it every 5 minutes, especially if I run an application in the debugger, test a few things (breakpoint, ...), stop, start, etc. All within a few seconds. Time sometimes seems to solve the issues. – atlaste Feb 24 '15 at 10:32
  • @atlaste: Glad(?) to hear it's not just me... – user541686 Feb 24 '15 at 10:59
  • @Mehrdad I'm pretty sure it has to do with a plugin, and I'm pretty sure where to look for. Can you tell me which of the following extensions you have: DevExpress, ANTS/Reflector, App insights, Behaviors SDK, SciTech memory profiler, Goto definition, MS Advertising SDK, ASP.NET scaffolding, Nuget, SHFB, Visual F#, Visual studio extensions for Windows library for Javascript, Windows phone 8.1, Workflow manager. – atlaste Feb 24 '15 at 11:05
  • @atlaste: If it's a plugin or extension, it has to be common across all the versions that it occurs on. Of those plugins, I have: Scaffolding; Nuget; Visual F# 2013; Editor extensions for HTML, CSS, and JavaScript... none of which seems relevant to VC++. – user541686 Feb 24 '15 at 11:08
  • 1
    @Mehrdad Agreed. Damnit; FYI I noticed procmon gave a lot and a lot of errors about sqlite in my users/temp folder (probably nuget considering your plugin list). However, the second iteration after removing all temp stuff the SQLite error is gone, but this annoying error continues. This bug is really as annoying as they come... – atlaste Feb 24 '15 at 11:13
  • Yeah it is :( and yeah I have nothing related to SQLite anywhere so that's definitely not relevant. ProcMon is totally useless here, the only hope I have left is [API Monitor](http://www.rohitab.com/apimonitor), but that's so much more painful to use (especially since I have no idea what the heck to monitor) that I'm not going to go about it. Feel free to give API Monitor a shot if you have any ideas... I've placed a bounty on this so as to motivate people as well. – user541686 Feb 24 '15 at 11:15
  • @Mehrdad OK, new info. After looking at netstat -a -n -b before, after and during correct execution, I disabled IPv6 on my PC. Result: it worked at first, then the error re-emerged after a few minutes. – atlaste Feb 24 '15 at 11:25
  • I happened to me a few times recently - I was working on some winsock code in VS2015 preview and, I believe, said problem happened after debugging/breaking execution when program was waiting on a blocking socket operation. VS restart helped though. – kerim Feb 25 '15 at 08:24
  • 1
    The network error message leads me to believe it is probably a Remote Debugging Monitor (msvsmon.exe) issue. If it happens only with 64bit, try backing up the 64bit msvsmon.exe and replace it with the 32bit version and see if that helps. – Rado Feb 26 '15 at 09:43
  • @Rado: That's the same thing I'd said in my [earlier comment](http://stackoverflow.com/questions/27871398/bizarre-behavior-with-visual-studios-debugger-the-network-location-cannot-be?noredirect=1#comment44161817_27871398) lol. I remember I tried that and for some reason it wasn't successful, but I don't remember why exactly. It's hard to reproduce though, so I won't try reproducing it again. – user541686 Feb 26 '15 at 09:49
  • alright.. you stated "at some point I tried to run the same project on both of them".. is your project in a network folder or location? – Brett Caswell Feb 27 '15 at 18:11
  • @BrettCaswell: no, there is nothing network-related anywhere. – user541686 Feb 27 '15 at 19:02
  • @Mehrdad I can confirm that this only happens in 64-bit mode. I suggest [reporting it as a bug](https://connect.microsoft.com/VisualStudio/Feedback) and see if the developers know what's going on. – Axalo Feb 28 '15 at 04:11
  • Just a wild guess (of course): have you seen this: https://answers.unrealengine.com/questions/63995/visual-studio-2013-unable-to-start-program.html it could be related to your network stack (virtual cards, IP settings, and most of all the winsock catalog). Even for 100% local processing, network layers may be in use (because there maybe cross process communications during debugging sessions) – Simon Mourier Mar 03 '15 at 05:55
  • @SimonMourier: I hadn't seen that, but I'm not sure how to diagnose/prove/disprove that... any suggestions on how I could go about checking to see if that's related? – user541686 Mar 03 '15 at 06:06
  • Maybe start with the winsock catalog 'netsh winsock show catalog'. Note anything fancy there (windowslive, bluetooth oems, apple's bonjour, etc). Also the network cards (windows phone emulator, virtual ethernet, custom vpns). You could also try to disable all your network cards and see if timeouts stop. – Simon Mourier Mar 03 '15 at 06:20
  • @SimonMourier: I see Bluetooth stuff and such, but they seem hardly relevant or fancy. I do have a VPN and such, I'll try playing around with stuff but it's already hard to reproduce the problem deterministically so I'm not sure if I'll succeed... – user541686 Mar 03 '15 at 06:28
  • @SimonMourier: In fact, for what it's worth, I can't reproduce the problem right now, despite the fact that I haven't changed anything :( this is very annoying... – user541686 Mar 03 '15 at 06:35
  • Have you considered asking in the Microsoft/vs forums? https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=visualstudio&filter=unanswered&sort=lastpostdesc – kfsone Aug 02 '16 at 04:23

5 Answers5

10

Ok, this is just so wrong

I also have issues with this bug, and in my case it occurred every other debug session. Which meant debug -> stop -> debug -> bug -> restart visual studio -> go to start (repeat every minute during the whole day).

Needless to say I was driven to find a solution. So yesterday I tried procmon, spend hours looking at API monitor differences, looked at plugins, netstat, etc, etc, etc. And found nothing. I gave up.

Today

Until today.

To track down a stupid bug in my program today, I launched appverifier. For my application, I ran the 'basics' tests and clicked save. After a few hours this led me to the bug in my program, which was something like this (extremely simplified version):

void* dst = _aligned_malloc(4096, 32);
memcpy(dst, src, 8192);

Obviously this is a bug and obviously it needed fixing. I noticed the error after putting a breakpoint on the memcpy line, which was not executed.

After a stop and 'debug' again I was surprised to find that I could actually debug the program for the second time. And now, several hours later, this annoying bug here hasn't re-emerged.

So what appears to be going on

So... apparently data from my program is bleeding through into the data or execution space of the debugger, which in turn appears to generate the bug.

I see you thinking: No, this shouldn't happen... you're right; but apparently it does.

So how to fix it? Basically fixing your program (more particular: heap corruption issues) seems to make the VS debugger bug go away. Using appverifier.exe (It's in Debugging tools for Windows) will give you a head start.

Why this works

Since VS2012, VC++ uses a different way to manage the heap. Hans Passant explains it here: Does msvcrt uses a different heap for allocations since (vs2012/2010/2013) .

What basically happens is that heap corruption will break your debugger. The AppVerifier basic settings will ensure that a breakpoint is triggered just before the application does something to corrupt the heap.

So, what happens now is that before the process will break the heap, a breakpoint will trigger instead, which usually means you will terminate the process. The net effect is that the heap will still be in-tact before you terminate your program, which means that your debugger will still function.

"Test"

  • Before using appverifier -- bug triggered every 2 minutes
  • While using appverifier -- VS debugger has been stable for 5 days (and counting)
Community
  • 1
  • 1
atlaste
  • 30,418
  • 3
  • 57
  • 87
  • Were you running the broken version in Debug mode, and did it actually cause the problem we're seeing while in Debug mode? I think I've only seen the problem in Release mode, so I'm not sure you're seeing what you think you're seeing. – user541686 Feb 25 '15 at 09:11
  • I had the problems in both Debug and Release mode, both x64. (running in the debugger of course, e.g. F5) – atlaste Feb 25 '15 at 09:25
  • 1
    Interesting o.O I'll +1, but I'm fairly sure it's wrong, because I've seen this happen on multiple projects, some of which I believe were quite simple. I don't think they all had memory bugs, but I can't rule it out right now... – user541686 Feb 25 '15 at 10:15
  • @Mehrdad I was just as surprised... the whole idea of application isolation is that these kinds of things Just Don't Happen. Still to be completely fair, the fact that Appverifier is now bound to the exe could also have solved the issue... still, that would surprise me just as much... – atlaste Feb 25 '15 at 10:37
  • This is not unusual since VS2012. Whether it explains the OP's problem requires one more detail: did this bug prevent you from restarting the debugger? – Hans Passant Feb 28 '15 at 09:51
  • @HansPassant Yes, in most cases it did. However, there were arbitrary occasions where I could restart it. Also I should probably note here that, since I've been using this solution using appverifier, the bug hasn't re-emerged at my pc (5 days now), where I used to get the exact same bug every minute or so. – atlaste Mar 02 '15 at 09:34
  • @HansPassant PS, I also tried process monitor, process explorer, api monitor, PDB's, killing msvsmon, and a bunch of other things. Without any results I might add. Most of the details are in the comments of the original post. It's a pretty nasty bug; appverifier seems to be the only magic bullet, since it prevents your heap from becoming corrupt in the first place - thereby solving the problem alltogether. – atlaste Mar 02 '15 at 09:39
2

This is an environmental problem of course. Always hard to troubleshoot, SysInternals' utilities like Process Monitor and Process Explorer are your primary weapons of choice. Some non-intuitive ways that a network error can be generated while debugging:

  • Starting with VS2012, the C runtime library had a pretty drastic modification that can cause very hard to diagnose mis-behavior if your program corrupts the heap. Much like @atlaste describes. Since time memorial, the CRT always created its own heap, underlying call was HeapCreate(). No more, it now uses GetProcessHeap(). This is very convenient, much easier now to deal with DLLs that were built with /MT. But with a pretty sharp edge, you can now easily corrupt the memory owned by Microsoft code. Not strongly indicated if you can't reattach a 64-bit program, you'd have to kill msvsmon.exe to clear up the corruption.

  • The Microsoft Symbol Server supplies PDBs for Microsoft executables. They normally have their source+line-number info stripped, but not all of them. Notably not for the CRT for example. Those PDBs were built on a build server owned by DevDiv in Redmond that had the source code on the F: drive. A few around that were built from the E: drive, Patterns+Practices uses that (unlikely in a C++ program). Your debugger will go look there to try to find source code. That usually ends well, it gives up quickly, but not if your machine uses those drive letters as well. Diagnose by clearing the symbol cache and disabling the symbol server with Tools + Options, Debugging, Symbols.

  • The winapi suffers from two nasty viral infections it inherited from another OS that add global state to any process. The PATH environmental variable and the default working directory. Use Control Panel + System + Advanced + Environment to have a look at PATH, copy/paste the content of the intentionally small textboxes into a text editor. Make sure it is squeaky clean, some paralysis at the usual mess is normal btw. Take no prisoners. Having trouble with the default directory is much harder to troubleshoot. Both should pop out when you use Process Monitor.

No slamdunk explanations, it is a tough problem, but dark corners you can look in.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
0

I have the same problem. Thought it was related to 64 bit console apps, where it is very easily triggered with almost any debug session. But, it also happens on 64 bit windows apps too. Now I am seeing it on 32 bit windows apps. I am running Windows 8.1 pro on a single desktop with the latest version of vs 2013 and no remote debugging. My (added) extensions are Visual Assist, Advanced Installer, ClangFormat, Code Alignment, Code Compare, Duplicate Selection, Productivity Power Tools 2013, and Visual SVN.

I discovered that the "Visual Studio 2013\Settings\CurrentSettings.vssettings" file gets corrupted. You can delete this file and recreate it by restarting VS or you can try to edit the XML. I then keep a copy of a good settings file that I use to replace when it gets corrupted again.

In my case, the corrupted line begins with

</ToolsOptionsSubCategory><ToolsOptionsSubCategory name="XAML" RegisteredName="XAML"

... and it is extremely long (I think this is why it is prone to corruption).

Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
  • Were actually able to fix the problem by fixing the settings file? While I can believe it I'm a little skeptical about this being the cause. – user541686 Jan 12 '15 at 23:02
  • In my case, the file gets corrupted to the point where even restarting VS doesn't allow the debugger to start the program. I have to restore the settings file in order to debug at all. I do not have enough information to assert how the corruption occurs. It appears to happen while the debugger is running. While debugging and paused/stepping through a console app, the console window flashes and/or disappears and the result is always a corrupt settings file and the end of debugging. – Frank Buquicchio Jan 13 '15 at 01:59
  • same problem occurs in vs 2015 ultimate preview (without any extensions) – Frank Buquicchio Jan 13 '15 at 18:39
  • By the way can you explain to me what the corruption actually is? The lines being long isn't actually a corruption... whitespace isn't mandatory. – user541686 Jan 14 '15 at 20:02
  • in the corruption that wouldn't resolve with a restart of VS, the line below was repeated about 4,500 times. While this looks suspicious, I cant be sure that this is the cause. – Frank Buquicchio Jan 16 '15 at 13:11
  • 1
    I attempted this approach, didn't fix a thing. Corruption or not, the annoying error persists. – atlaste Feb 24 '15 at 11:54
0

I just disabled in the Menu

Tools > Options

Debugging > Edit and Continue

Native-only options > Enable native Edit and Continue

and now it does not give the that stupid error which was preventing the starting of the debuggee application.

Community
  • 1
  • 1
sergiol
  • 4,122
  • 4
  • 47
  • 81
0

I also had the same problem with VS2015. It was so frustrating that a simple Hello World program gave this error when I ran debugger for the second time. Tried uninstall and reinstall and didn't work.

Finally, the solution mentioned in https://social.msdn.microsoft.com/Forums/vstudio/en-US/8dce0952-234f-4c18-a71a-1d614b44f256/visual-studios-2012-cannot-findlaunch-project-exe?forum=vsdebug

worked. Reset all visual studio settings using Tools->Import and Export settings. Now the issue is not occurring.