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

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

Closed
mjbvz opened this issue Apr 18, 2017 · 21 comments
Closed

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

mjbvz opened this issue Apr 18, 2017 · 21 comments

Comments

@mjbvz
Copy link

mjbvz commented Apr 18, 2017

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

@Cnordbo
Copy link

Cnordbo commented Apr 18, 2017

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

@DustinCampbell
Copy link
Member

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

@DustinCampbell
Copy link
Member

This is probably a special case of #785.

@Cnordbo
Copy link

Cnordbo commented Apr 18, 2017

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.

@ehajri
Copy link

ehajri commented Nov 18, 2017

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
Copy link

ehajri commented Dec 2, 2017

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

@DustinCampbell
Copy link
Member

cc @rchande

@Gaulomatic
Copy link

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.

@pczzz
Copy link

pczzz commented Jan 9, 2019

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

@ethan-deng
Copy link

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

@fasetto
Copy link

fasetto commented Aug 21, 2020

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

@ghandmann
Copy link

ghandmann commented Jul 6, 2022

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.

@BabyboB1994
Copy link

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

@Kazinix
Copy link

Kazinix commented Sep 6, 2022

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.

@cossieB
Copy link

cossieB commented Sep 9, 2022

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

@MrStLouis
Copy link

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

@blogcraft
Copy link

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

@jano-petras
Copy link

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.

@GeekChanaa
Copy link

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

@ghandmann
Copy link

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

@mikadumont
Copy link
Contributor

We've made lots of updates to the C# extension since this issue was filed. Please file a new issue if you're still experiencing this with updated logs.

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

No branches or pull requests