Open paulpottertasd opened 4 years ago
Today i noticed the exact same issue.
Everytime i create a new file and create a new class inside of it, i get the "Namespace already contains a definition" error.
Compiling the exact same state via dotnet build
works flawless.
1) Create a new console app with dotnet new console
2) Load the new app via VSCode
3) In the Project-Directory-Tree right click and select "New File"
4) Name the new file "MyClass.cs"
5) Add this code to the new class:
namespace MyApp;
public class MyClass { }
6) Observe error The namespace "MyApp" already contains a definition for "MyClass"
$ code-insiders --version
1.68.0-insider
2260d7cca34384a2838c728850afdd38113ddb47
x64
$ code-insiders --list-extensions --show-versions
aaron-bond.better-comments@3.0.0
akamud.vscode-theme-onelight@2.2.3
code-intelligence.ci-fuzz@2.27.0
codezombiech.gitignore@0.7.0
davraamides.todotxt-mode@1.4.31
dbaeumer.vscode-eslint@2.2.2
eamodio.gitlens@12.0.7
EditorConfig.EditorConfig@0.16.4
enkia.tokyo-night@0.8.4
Equinusocio.vsc-community-material-theme@1.4.2
Equinusocio.vsc-material-theme@33.2.0
equinusocio.vsc-material-theme-icons@1.2.2
formulahendry.dotnet-test-explorer@0.7.7
gamunu.vscode-yarn@2.1.0
GitHub.github-vscode-theme@6.0.0
GitLab.gitlab-workflow@3.44.2
GraphQL.vscode-graphql@0.4.9
hbenl.vscode-mocha-test-adapter@2.13.5
hbenl.vscode-test-explorer@2.21.1
jchannon.csharpextensions@1.3.1
jeff-hykin.better-cpp-syntax@1.15.14
k--kato.docomment@0.1.31
liviuschera.noctis@10.40.0
max-SS.Cyberpunk@1.2.14
mortenhenriksen.perl-debug@0.6.3
ms-azuretools.vscode-docker@1.22.0
ms-dotnettools.csharp@1.25.0
ms-vscode-remote.remote-containers@0.238.0
ms-vscode-remote.remote-ssh@0.80.0
ms-vscode-remote.remote-ssh-edit@0.80.0
ms-vscode-remote.remote-wsl@0.66.3
ms-vscode.cmake-tools@1.10.5
ms-vscode.cpptools@1.10.4
ms-vscode.cpptools-themes@1.0.0
ms-vscode.test-adapter-converter@0.1.6
netcorext.uuid-generator@0.0.5
octref.vetur@0.35.0
PKief.material-icon-theme@4.17.0
redhat.vscode-commons@0.0.6
redhat.vscode-yaml@1.7.0
richterger.perl@2.3.0
RobbOwen.synthwave-vscode@0.1.11
twxs.cmake@0.0.17
vsciot-vscode.vscode-arduino@0.4.12
zxh404.vscode-proto3@0.5.5
$ dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.101
Commit: ef49f6213a
Runtime Environment:
OS Name: ubuntu
OS Version: 21.10
OS Platform: Linux
RID: ubuntu.21.10-x64
Base Path: /usr/share/dotnet/sdk/6.0.101/
Host (useful for support):
Version: 6.0.1
Commit: 3a25a7f1cc
.NET SDKs installed:
2.1.818 [/usr/share/dotnet/sdk]
3.1.416 [/usr/share/dotnet/sdk]
5.0.404 [/usr/share/dotnet/sdk]
6.0.101 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.30 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.22 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.22 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.13 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
I'm observing the same issue following a tutorial on Signlr at this link (FYI I use VSCode for linux):
$ code --version
1.67.0
57fd6d0195bb9b9d1b49f6da5db789060795de47
x64
My fix is I delete the class (the first one I've added to the project) and recreate it, copy-pasting the code verbatim. Then the error disappears
I have experienced this issue too, i had to restart the language server. this issue doesn't always occur though.
Environment data
dotnet --info
output: VS Code version: 1.49.3 C# Extension version:1.23.2OmniSharp log
Steps to reproduce
The very first class that I create on startup throws an error that the namespace already contains a definition for that new class. It doesn't happen after the first one.
Expected behavior
Actual behavior