Attach to Unity not working with Visual Studio Professional 2017

I have been using VS Pro 2017 for 2 years straight on Windows 10 with the same computer, and all of a sudden the Attach to Unity is not working.

VS Pro shows the orange bar at the very bottom when I click the Attach to Unity button, but then switches back to blue and shows this in the log:

The program 'Unity' has exited with code 1 (0x1).

after loading all the modules.

This happened once before, a month ago, and I resolved it by uninstalling VS Pro 2017 and reinstalling it. I just tried that again, but it did not work this time.

Anyone have experience with this, or have any ideas?

I have tried:

  1. uninstalling and reinstalling VS Pro 2017
  2. modifying VS Pro 2017 to remove and then re-add the “Game development with Unity” package
  3. starting Unity as an admin
  4. changing the editor in Unity Preferences to something else, then back to VS Pro 2017
1 Like

Im having this issue right now. It’s total randomness. Sometimes it’s working (rarely) sometimes cannot be solved.

Are you trying to attach to the Editor or a Player? Do you have script debugging enabled if you are attempting to attach to a player? Similar for the editor but it’s called debug mode.

This kind of error sounds like the Unity process does not have the debugger-agent thread running and awaiting connections from the IDE.

I’m trying to attach it to Editor, script debugging yes and it is already working for the first time, and you stop and run again, it doesn’t work (total randomness). The only way to solve it, removing all of project files (.sln, csproj) and restart Unity to regenerate them. This solves the problem %100, but later, it will happen again somehow.

Hrm… that’s not good. How long does it take for the issue to reappear after regenerating the solution files? If possible could you capture a memory dump of the unity editor process when you are unable to connect a debugger? I’d like to take a look to see the current state of the threads when this occurs. What version of Unity are you using?

I cannot reproduce it anymore :eyes:

I’m having the exact same issue as erenaydin.

  1. Attach debugger in VS and accept the debug session in Unity
  2. Play
  3. Everything works fine.
  4. Exit debugger in VS
  5. Ohh, I wasn’t finished debugging, try to attach it again
  6. It tries to start but exits with code 0x01

Sometimes you have to toggle the debug mode in unity back and forth with the icon in the lower right corner.

Edit: Only a full restart of Unity and VS seems to fix it.

w/ 2023.2.20f

Yeah that doesn’t sound right. Next time this happens (you can’t reattach the debugger) please capture a memory dump of Unity and DM it to me. I’d like to investigate to see where things are stuck. I’m suspicious that the debugger agent thread has either died or is waiting for input for some reason.

Hi Alex, thanks for helping out with this!

I’m encountering the same issue, except that for me it happens extremely consistently when I have a break point in a Burst-compiled job. Here’s my experience with this:

  • Normally, the first time in a session I place a break point in a Burst-compiled job it would work just fine until the first time I stop the debugger. From then on, as long as there’s a break point in any Burst-compiled job, enabling the debugger will immediately stop it with the output message The program 'Unity' has exited with code 1 (0x1).
  • As was mentioned in this thread, the only thing that ever seems to solve it (until the next time it expectedly breaks) is a full restart of both Unity and VS
    • At the moment, this is the first time that not this, or a full computer restart, or a VS update have fixed the issue. Right now, the debugger keeps stopping immediately as long as I have a break point in Burst-compiled code, and nothing seems to fix it even for one debugging session
  • Removing the [BurstCompile] attribute from the struct containing the break point will allow the debugger to work again
  • Unity version 2022.2.17
    • Visual Studio Editor package version 2.0.22
  • Visual Studio Community 2022 version 17.11.1

I’ll send you a DM with a memory dump of the Unity process as I see you requested from another user here. If there’s any other information I can add here, please say so; it’s quite easy for me to reproduce this issue.

Thank you for your assistance!

1 Like