views:

187

answers:

2

Occasionally (usually after having updated my .sln file in source control) I get a strange Visual Studio error wherein I'm unable to open some of my files. The files in question show up in the appropriate project, but trying to open them results in an error dialog saying "A file of that name is already open."

This is virtually identical to http://stackoverflow.com/questions/923235/visual-studio-project-with-that-name-already-opened-in-the-solution, except for files, not projects. The solution given there was does not fix this.

+1  A: 

Do you have any linked files in the solution?

Visual Studio has an invariant that only a single file of a given path can be open at one time. This invariant is hit most often when you have a linked file in your project / solution and attempt to open both the original and one of it's linked references.

JaredPar
No linked files AFAIK.
JSBangs
+1  A: 

Visual Studio internally maintains a list of currently opened files, to avoid problems caused by opening files more than once. Any number of things (crashes, reboots, updating files in source control outside of VS) can cause this list to become corrupted.

In any case, the problem can be fixed by deleting the hidden Solution.suo file which is in the same directory as your Solution.sln file. This will cause you to lose your current workspace state (open files, window layout, etc.), but it won't have any other adverse affects on your solution.

This is a hidden file, so to see or delete it you either have to enable viewing hidden files in Explorer or use del /AH Solution.suo on the command-line.

JSBangs
Using VS2008 on Vista, I deleted the Solution.sln.cache file to the same effect.
willoller