Omnisharp-vscode: Rename .cs file -> The namespace 'Namespace' already contains a definition for 'ClassName' [netcoreapp1.0]

Created on 27 Sep 2016  Â·  23Comments  Â·  Source: OmniSharp/omnisharp-vscode

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview2-003121)

Product Information:
 Version:            1.0.0-preview2-003121
 Commit SHA-1 hash:  1e9d529bc5

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64

VS Code version: 1.5.3
C# Extension version: 1.4.1

Steps to reproduce

  1. Open dotnet core solution from base solution directory
  2. Open any .cs file
  3. Rename it
  4. Make a minor, valid change to the code so OmniSharp reevaluates it
  5. Observe as errors appear: Class name has The namespace 'Namespace' already contains a definition for 'ClassName' [netcoreapp1.0]. Methods have Type 'ClassName' already defines a member called 'MethodName' with the same parameter types [netcoreapp1.0]
Bug Resolved-Fixed

Most helpful comment

@THuffam

Restarting Omnisharp also works. CTRL + SHIFT + P, then 'Restart Omnisharp'. Faster than restarting VSCode at least 😄

All 23 comments

Experienced same issue.

Same error occuring for me - rename a .cs file and get the errors mentioned above. Need to restart VS Code to fix.

@THuffam

Restarting Omnisharp also works. CTRL + SHIFT + P, then 'Restart Omnisharp'. Faster than restarting VSCode at least 😄

@mausworks Thanks for sharing! it works!

This is fixed with the latest beta v1.13.0-beta4. You can install it by following the instructions here.

This is fixed only in beta? because I am still facing this issue with v1.13.

Yes, this was fixed in 1.13. @rchande?

@ehajri It should be fixed. Can you provide more information about what's happening to you?

@DustinCampbell, @rchande I removed the extension and it appears to be 1.13.1 now.
It seems to be fixed (or maybe a reboot did it, not sure). I'll update this if it reoccurs.

Thanks for the update @ehajri. I've seen some evidence of strange install issues with VS Code 1.18 that seem to "correct" themselves later. Hopefully, that's all this was.

I'm having this problem using C# extension 1.13.1 (and VSCode 1.19 Insiders) in a particular scenario.

Steps

  1. Rename a class using F2 within the buffer.
  2. Rename the filename using F2 in the explorer to match the new class name.

I get a squiggly line on the classname for the same "Namespace already contains a definition" error.

WebmOfRepro.zip

EDIT:
It seems to happen only with multiple root folders? I'm not sure.
Here's the minimum code/files I could strip down to and still be able to reproduce it:
renameBug.zip

Odd, but I experienced this today, too. Restructuring my project directory triggered this. Restarting VSCode fixed it.

@johncrisostomo What extension version are you on?

Had the same issue today.

VS Code info

Version: 1.27.2 (user setup)
Commit: f46c4c469d6e6d8c46f268d1553c5dc4b475840f
Date: 2018-09-12T16:17:45.060Z
Electron: 2.0.7
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64
OS: Windows 10 Pro

OmniSharp

Version: 1.16.1.

Workaround
OmniSharp restart helped.

Case

  • Create a class description.
  • Use it in another class.
  • Use F2 to refactor the class name (from the another class).
  • Go to Explorer in VS Code and rename file with the class description.
  • Get the error.

omnisharp error
i was experiencing this as well, every time i rename a file the type inside it appears to be duplicated

code --version
1.29.1
bc24f98b5f70467bc689abf41cc5550ca637088e
x64

code --list-extensions --show-versions
Angular.[email protected]
AureliaEffect.[email protected]
behzad88.[email protected]
christian-kohler.[email protected]
coolbear.[email protected]
EditorConfig.[email protected]
eg2.[email protected]
HookyQR.[email protected]
jchannon.[email protected]
jock.[email protected]
ms-mssql.[email protected]
ms-python.[email protected]
ms-vscode.[email protected]
ms-vscode.[email protected]
msjsdiag.[email protected]
msjsdiag.[email protected]
PeterJausovec.[email protected]

i also changed
"omnisharp.path": null
to
"omnisharp.path": "latest"

i think i was using a default(older) omnisharp version but this didn't solved the issue
now i've
OmniSharp Version = 1.32.9-beta.10

the issue appears ONLY if i work with vscode workspace,

### steps to reproduce:

mkdir test
cd test
dotnet new classlib -f netstandard2.0 -n omnitest
code .
from inside vs code
File -> Save Workspace As…
chose where the test folder is
name the workspace "test.code-workspace"

wait for omnisharp to complete to load and process the project
you should see a file "class1.cs" created by the classlib template by dotnet new

select it and rename it "class2.cs"

you'll see that a red squiggle appear below
public class Class1
problems tab will report
{
"resource": "/c:/temp/omnisharp/omnitest/Class2.cs",
"owner": "csharp",
"severity": 8,
"message": "The namespace 'omnitest' already contains a definition for 'Class1' [omnitest]",
"startLineNumber": 5,
"startColumn": 18,
"endLineNumber": 5,
"endColumn": 24
}

as i said if i open the folder with "code . " instead of using the workspace file the issue didn't appear.
it is strictly related to the use of workspaces.

I hope this help to understand where the issue is, it is really annoying to keep restarting omnisharp

@PhotoAtomic Oh, you might be on to something. If I open a single folder, I can rename without issue, but if I then add another folder (if that has any importance, via the side pane Explorer -> Right-Click -> Add Folder to workspace), then error will appear on renames.

@THuffam

Restarting Omnisharp also works. CTRL + SHIFT + P, then 'Restart Omnisharp'. Faster than restarting VSCode at least

This worked for me.

@THuffam

Restarting Omnisharp also works. CTRL + SHIFT + P, then 'Restart Omnisharp'. Faster than restarting VSCode at least 😄

This works, thanks for sharing!

The same issue here, And restart vs code or Omnisharp doesn't work for me. So odd

The same issue here, And restart vs code or Omnisharp doesn't work for me. So odd

Running a VS Code with admin rights "helps".

3 years later, still have to restart omnisharp after a file rename. Supporting these "advanced" use cases must be real hard.

Original bug is still present. Also reproducible on copying and pasting a file containing a class. And as of today, reproducible on adding a new file and adding a new class.

Looks like latest stable:
extensionsms-dotnettools.csharp-1.23.0.omnisharp1.36.1OmniSharp.exe
Windows 10
VS Code 1.48.0
.net core 3.1 project

Was this page helpful?
0 / 5 - 0 ratings