vscode-csharp
vscode-csharp copied to clipboard
The namespace *namespace* Already contains a definition for *Controller*
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:
- Create a new Controller (C#, MVC app, im using the template from "dotnet new react"
- Delete the controller
- Re-create it
Error: Says that it already exists, and shows an error in the UI
Copied from original issue: Microsoft/vscode#24970
I will throw in a temp fix as well: restart vscode.
Invoking the "Restart OmniSharp" command will also fix it as a workaround.
This is probably a special case of https://github.com/OmniSharp/omnisharp-vscode/issues/785.
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.
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:
Got this:
However, after restarting OmniSharp:
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 ..
cc @rchande
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.
For me it worked, when I opened VSCode as Admin(right click, Run as Administator )
Restarting Omnisharp worked for me. Press CTRL + SHIFT + P, then select 'Restart Omnisharp' from the list
In this week, I'm getting this error frequently. But I'm not sure, when or why it is happening. 🤔
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.
Had the same issue. Restarting the VS Code has fixed it.
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.
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
FWIW I was able to resolve the issue via the option OmniSharp: Select Project
where any selection "fixed" it.
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....
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.
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 ...
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