JSBձոգչ
JSBձոգչ

Reputation: 41388

Visual Studio - Fixing the error "A file of that name is already open"

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 Why does it say "Project with that name already opened in the solution"?, except for files, not projects. The solution given there was does not fix this.

Upvotes: 12

Views: 12926

Answers (4)

Mitul Rajai
Mitul Rajai

Reputation: 1

Open csproj file of the project and delete following lines:

<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>

These lines are most probably created due to project is added to visual svn i.e. when project/solution is added to source control project/solution files are updated to include source control integration info and these lines are added which causes issues.

Delete these lines and just reload your project (or solution), this should fix issue.

Upvotes: -1

Pratham
Pratham

Reputation: 71

Delete the hidden .suo file and edit the .csproj file to remove the lines below:

<SccProjectName>Svn</SccProjectName>
<SccLocalPath>Svn</SccLocalPath>
<SccAuxPath>Svn</SccAuxPath>
<SccProvider>SubversionScc</SccProvider>

Now, reopen the solution to solve the issue.

Upvotes: 3

JSBձոգչ
JSBձոգչ

Reputation: 41388

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.

Upvotes: 13

JaredPar
JaredPar

Reputation: 755457

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.

Upvotes: 1

Related Questions