Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Visual Studio

Visual Studio: Fix ‘Unable to Start Program’ After Switching Git Branches Without Reinstalling

- 30.08.26 | 31.08.26 - ErcanOPAK

๐Ÿ› ๏ธ Switched Branches? Clean Before You Debug

Switching Git branches in Visual Studio and immediately hitting F5 sometimes throws “Unable to start program… The system cannot find the file specified” — even though the code builds fine. The cause is almost always stale build output, not a broken project.

๐Ÿ” Why This Happens

Git only tracks source files, not the bin/ and obj/ folders
(they're correctly gitignored). When you switch branches, if the
target framework, output path, or project references differ even
slightly between branches, Visual Studio's incremental build can
end up pointing at an exe/dll path that no longer matches what's
actually configured - or a half-updated obj/ cache confuses MSBuild
about what needs rebuilding.

โœ… The Fix, in Order of Effort

  • Try the cheapest fix first: Build โ†’ Clean Solution, then Build โ†’ Rebuild Solution.
  • Still broken? Close Visual Studio and manually delete the bin/ and obj/ folders in the project directory, then reopen and rebuild.
  • Still broken after that? Check whether the branches actually target different .NET versions/SDKs — that requires more than a clean, it needs the right SDK installed.

๐Ÿงน Manual Clean (PowerShell, run from solution root)

Get-ChildItem .\ -Include bin,obj -Recurse | Remove-Item -Recurse -Force

# Then in Visual Studio:
# Build -> Rebuild Solution
# Debug -> Start Debugging (F5)

โš ๏ธ Make This Automatic Going Forward

  • Visual Studio has no built-in “auto-clean on branch switch” — but you can add a simple pre-build check or just make Clean-before-Rebuild a habit after any branch switch that touches project files (.csproj).
  • If you use Git hooks, a post-checkout hook that deletes bin/obj can automate this project-wide.

“Unable to start program” right after a branch switch is Visual Studio pointing at a file path that no longer matches reality — Clean + Rebuild fixes that mismatch faster than any deeper troubleshooting.

โ€” Developer Tip

Related posts:

Visual Studio Builds Succeed but App Runs Old Code

5 Editing Hacks for Visual Studio

Visual Studio 2022: The Hidden Power of CodeLens That 10x Developers Actually Use

Post Views: 8

Post navigation

SQL Server: Recover an Accidental UPDATE Without WHERE Using the Transaction Log
SQL Server: Why NOLOCK Silently Returns Duplicate or Missing Rows

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

October 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Sep    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (952)
  • How to add default value for Entity Framework migrations for DateTime and Bool (939)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (837)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (624)
  • Add Constraint to SQL Table to ensure email contains @ (590)
  • Average of all values in a column that are not zero in SQL (553)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (526)
  • Find numbers with more than two decimal places in SQL (468)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps
  • Photoshop: Fix a Color Profile Mismatch That Makes Printed Output Look Nothing Like What You Saw On Screen
  • WordPress: Fix Search Results That Return Pages From a Theme You Deactivated Months Ago
  • Visual Studio: Fix a Test Project That Builds Fine Alone but Fails to Discover Any Tests After a NuGet Restore
  • ASP.NET Core: Fix a File Upload That Times Out on Slow Connections Only Because Kestrel’s Minimum Data Rate Feature Kicked In
  • JavaScript: Fix an Array Destructuring Default Value That Silently Never Applies Because null Was Passed Instead of Undefined

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (952)
  • How to add default value for Entity Framework migrations for DateTime and Bool (939)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (837)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com