vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

The namespace *namespace* Already contains a definition for *Controller*

Open mjbvz opened this issue 7 years ago • 16 comments

From @Cnordbo on April 18, 2017 19:52

  • VSCode Version: Code 1.11.2 (6eaebe3b9c70406d67c97779468c324a7a95db0e, 2017-04-13T08:03:11.395Z)
  • OS Version: Windows_NT ia32 10.0.14393
  • Extensions:
Extension Author Version
gitignore codezombiech 0.5.0
vscode-express Compulim 0.0.5
git-project-manager felipecaputo 1.2.1
vscode-nuget-package-manager jmrog 1.1.2
mssql ms-mssql 0.3.0
csharp ms-vscode 1.8.1
vscode-icons robertohuertasm 7.5.1
gitblame waderyan 1.3.0

Steps to Reproduce:

  1. Create a new Controller (C#, MVC app, im using the template from "dotnet new react"
  2. Delete the controller
  3. Re-create it

Error: Says that it already exists, and shows an error in the UI

Copied from original issue: Microsoft/vscode#24970

mjbvz avatar Apr 18 '17 19:04 mjbvz

I will throw in a temp fix as well: restart vscode.

Cnordbo avatar Apr 18 '17 20:04 Cnordbo

Invoking the "Restart OmniSharp" command will also fix it as a workaround.

DustinCampbell avatar Apr 18 '17 20:04 DustinCampbell

This is probably a special case of https://github.com/OmniSharp/omnisharp-vscode/issues/785.

DustinCampbell avatar Apr 18 '17 20:04 DustinCampbell

I think what i did the first time i encountered it was to name the file something like "Particle", and the class "ParticleController" - i then renamed the file, and it gave this error. Altough i couldnt reproduce this scenario.

Cnordbo avatar Apr 18 '17 20:04 Cnordbo

Not sure if it is related to this issue, but I was playing with xUnit (install, uninstall, create diff project within the same solution, removed old xUnit, etc..).

dotnet info:

.NET Command Line Tools (2.0.2)

Product Information:
 Version:            2.0.2
 Commit SHA-1 hash:  a04b4bf512

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.13
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.0.2/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

OmniSharp/C# version: screen shot 2017-11-17 at 7 36 13 pm

Got this: rename error

However, after restarting OmniSharp: after omni restart

ehajri avatar Nov 18 '17 01:11 ehajri

It happened again. I just moved the entire solution into another file:

- Solution
 - .sln
 - project1
 - project2

To:

- Folder
 - Solution
  - .sln
  - project1
  - project2

and the same error The namespace .. already contains a definition for ..

ehajri avatar Dec 02 '17 09:12 ehajri

cc @rchande

DustinCampbell avatar Dec 04 '17 20:12 DustinCampbell

Any solution other than restarting OmniSharp? This is not critical but really annoying since OmniSharp needs a reasonable amount of time to restart on larger solutions.

Gaulomatic avatar Mar 26 '18 20:03 Gaulomatic

For me it worked, when I opened VSCode as Admin(right click, Run as Administator )

pczzz avatar Jan 09 '19 07:01 pczzz

Restarting Omnisharp worked for me. Press CTRL + SHIFT + P, then select 'Restart Omnisharp' from the list

ethan-deng avatar Mar 13 '19 17:03 ethan-deng

In this week, I'm getting this error frequently. But I'm not sure, when or why it is happening. 🤔

fasetto avatar Aug 21 '20 11:08 fasetto

Since recently i get the same error/behavior for every new file with a new C# class i create. The moment i finish my public class MyClass { } ceremony i get the error The namespace 'Blah' already contains a definition for 'MyClass'. Restarting Omnisharp makes the error go away.

Adding another new class in the already existing file after restarting Omnisharp does not trigger the error again.

Edit: Just realized that renaming the file after everything was fine brings back the same error.

ghandmann avatar Jul 06 '22 20:07 ghandmann

Had the same issue. Restarting the VS Code has fixed it.

BabyboB1994 avatar Aug 31 '22 06:08 BabyboB1994

It seems to happen when I connect my account for VSCode -- I use GitHub account. What's weirder is, after connecting/disconnecting the account, I have to test and restart VSCode twice or thrice for the problem to happen/not happen. My test involves creating a .cs file then creating a class in that file.

I'm still trying to figure out if it has something to do with syncing OmniSharp settings.

Kazinix avatar Sep 06 '22 09:09 Kazinix

This happens every time I create a new class in a new file. Restarting OmniSharp works but it gets tedious really quickly.

So I've had to resort to workarounds like creating my classes in bulk before restarting and putting related ones in the same file.

v1.25

cossieB avatar Sep 09 '22 09:09 cossieB

FWIW I was able to resolve the issue via the option OmniSharp: Select Project where any selection "fixed" it.

MrStLouis avatar Sep 29 '22 01:09 MrStLouis

Every time I create, move, rename a class, interface etc. this happens... to be able to work I have to restart omnisharp 50 times a day....

blogcraft avatar Dec 06 '22 15:12 blogcraft

This issue does not happen if a new .cs file is added from elsewhere, not from Visual Studio Code. I use touch MyNewFile.cs from terminal. It appears in VS Code automatically, and adding class definition into this file does not cause this issue.

jano-petras avatar Feb 25 '23 03:02 jano-petras

anybody still getting the same error in vs code 1.79 ? Because I'm still having the same issue in this version, Restaring omnisharp fixes the issue for me too ...

GeekChanaa avatar Jul 03 '23 11:07 GeekChanaa

I was not able to quickly reproduce the problem again today. But had to manually switch to use OmniSharp first.

VS Code About:

Version: 1.81.1
Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794
Date: 2023-08-09T22:18:39.991Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Linux x64 5.15.0-86-generic
OmniSharp: 1.39.10-net6.0

ghandmann avatar Oct 17 '23 08:10 ghandmann