Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jlost opened this issue Sep 27, 2016 · 27 comments

Comments

@jlost
Copy link

jlost commented Sep 27, 2016

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]
@matthamil
Copy link

matthamil commented Oct 7, 2016

I had this same issue, see #803.

@gulshan
Copy link

gulshan commented Dec 15, 2016

Experienced same issue.

@THuffam
Copy link

THuffam commented Jul 10, 2017

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

@DustinCampbell
Copy link
Member

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

@ehajri
Copy link

ehajri commented Nov 14, 2017

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

@DustinCampbell
Copy link
Member

Yes, this was fixed in 1.13. @rchande?

@rchande
Copy link

rchande commented Nov 15, 2017

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

@ehajri
Copy link

ehajri commented Nov 15, 2017

@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.

@DustinCampbell
Copy link
Member

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.

@dubeg
Copy link

dubeg commented Nov 26, 2017

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

@johncrisostomo
Copy link

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

@rchande
Copy link

rchande commented Jun 1, 2018

@johncrisostomo What extension version are you on?

@colotiline
Copy link

colotiline commented Oct 4, 2018

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.

@PhotoAtomic
Copy link

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.ng-template@0.1.11
AureliaEffect.aurelia@1.0.3
behzad88.Aurelia@1.2.2
christian-kohler.path-intellisense@1.4.2
coolbear.systemd-unit-file@1.0.2
EditorConfig.EditorConfig@0.12.5
eg2.tslint@1.0.40
HookyQR.beautify@1.4.7
jchannon.csharpextensions@1.3.0
jock.svg@0.1.4
ms-mssql.mssql@1.4.0
ms-python.python@2018.11.0
ms-vscode.csharp@1.17.1
ms-vscode.PowerShell@1.10.0
msjsdiag.debugger-for-chrome@4.11.1
msjsdiag.debugger-for-edge@1.0.6
PeterJausovec.vscode-docker@0.4.0

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

@dubeg
Copy link

dubeg commented Dec 6, 2018

@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.

@NickChlam
Copy link

@THuffam

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

This worked for me.

@robwillup
Copy link

@THuffam

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

This works, thanks for sharing!

@Abdulkareem83
Copy link

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

@toptulla
Copy link

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".

@hk1ll3r
Copy link

hk1ll3r commented May 23, 2019

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

@poctob
Copy link

poctob commented Aug 16, 2020

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:
extensions\ms-dotnettools.csharp-1.23.0.omnisharp\1.36.1\OmniSharp.exe
Windows 10
VS Code 1.48.0
.net core 3.1 project

@ghost
Copy link

ghost commented Mar 5, 2022

The same issue.
code --version
1.65.0
b5205cc8eb4fbaa726835538cd82372cc0222d43
x64

code --list-extensions --show-versions
donjayamanne.githistory@0.6.19
icsharpcode.ilspy-vscode@0.13.1
idleberg.openvpn@0.2.3
MS-CEINTL.vscode-language-pack-ru@1.65.1
ms-dotnettools.csharp@1.24.1
ms-dotnettools.vscode-dotnet-runtime@1.5.0
ms-python.python@2022.2.1924087327
ms-python.vscode-pylance@2022.3.0
ms-toolsai.jupyter@2022.2.1020642448
ms-toolsai.jupyter-keymap@1.0.0
ms-toolsai.jupyter-renderers@1.0.6
PrzemyslawOnak.pimp-my-avalonia@0.0.1

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 21.04
Release: 21.04
Codename: hirsute

@blogcraft
Copy link

blogcraft commented Dec 6, 2022

Same issue... getting tired of omnisharp, many years and no solution. Considering transition my development team to Visual Studio.

Project using .NET 6 and .NET 7
omnisharp v1.25.2

@TheBuzzSaw
Copy link

Still no solution for this? It happens to this very day.

/.vscode/extensions/ms-dotnettools.csharp-1.25.8-linux-x64/.omnisharp/1.39.6-net6.0/OmniSharp.dll

@ghost
Copy link

ghost commented Sep 25, 2023

I downgraded C# add-on to v1.24.1, and it is a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.