This is an odd one. I've spent a number of hours trying to track down the source of this error and I'm still not 100% positive, but it looks like an issue with this extension.
While working on a Razor Pages project, we created a page named ExperimentLeg.cshtml with the corresponding ExperimentLeg.cshtml.cs file. The .cshtml file is showing an error about not being able to find the Model, and the .cs file has none of the normal OmniSharp extension helpers like reference counts.
By simply changing the name of the .cs page to ANYTHING that does not end with a lowercase "g" (like ExperimentLe.cshtml.cs), this problem goes away.
The project builds and runs without error. This appears to be an issue inside VS Code with this extension.
The name of the page is key. TestPag is NOT a typo.
I've tested this on 4 computers (3 macOS and 1 Windows).
Run the following terminal commands:
mkdir TestApp
cd TestApp
dotnet new webapp
dotnet new page --name TestPag --namespace TestApp.Pages --output Pages
Open the project in VS Code (with only this extension enabled) and observe an error on TestPag.cshtml.
{
"resource": "/Users/alexhaines/Projects/TestApp/Pages/TestPag.cshtml",
"owner": "csharp",
"code": "CS0234",
"severity": 8,
"message": "The type or namespace name 'TestPagModel' does not exist in the namespace 'TestApp.Pages' (are you missing an assembly reference?) [TestApp]",
"source": "csharp",
"startLineNumber": 2,
"startColumn": 15,
"endLineNumber": 2,
"endColumn": 27
}
There are also 4 errors in the Problems view for TestPag.cshtml__bg__virtual.cs
{
"resource": "/Users/alexhaines/Projects/TestApp/Pages/TestPag.cshtml__bg__virtual.cs",
"owner": "csharp",
"code": "CS0234",
"severity": 8,
"message": "The type or namespace name 'TestPagModel' does not exist in the namespace 'TestApp.Pages' (are you missing an assembly reference?) [TestApp]",
"source": "csharp",
"startLineNumber": 55,
"startColumn": 85,
"endLineNumber": 55,
"endColumn": 97
}
{
"resource": "/Users/alexhaines/Projects/TestApp/Pages/TestPag.cshtml__virtual.cs",
"owner": "csharp",
"code": "CS0234",
"severity": 8,
"message": "The type or namespace name 'TestPagModel' does not exist in the namespace 'TestApp.Pages' (are you missing an assembly reference?) [TestApp]",
"source": "csharp",
"startLineNumber": 56,
"startColumn": 95,
"endLineNumber": 56,
"endColumn": 107
}
{
"resource": "/Users/alexhaines/Projects/TestApp/Pages/TestPag.cshtml__virtual.cs",
"owner": "csharp",
"code": "CS0234",
"severity": 8,
"message": "The type or namespace name 'TestPagModel' does not exist in the namespace 'TestApp.Pages' (are you missing an assembly reference?) [TestApp]",
"source": "csharp",
"startLineNumber": 56,
"startColumn": 201,
"endLineNumber": 56,
"endColumn": 213
}
{
"resource": "/Users/alexhaines/Projects/TestApp/Pages/TestPag.cshtml__virtual.cs",
"owner": "csharp",
"code": "CS0234",
"severity": 8,
"message": "The type or namespace name 'TestPagModel' does not exist in the namespace 'TestApp.Pages' (are you missing an assembly reference?) [TestApp]",
"source": "csharp",
"startLineNumber": 57,
"startColumn": 30,
"endLineNumber": 57,
"endColumn": 42
}
If you rename TestPag.cshtml.cs to TestPage.cshtml.cs, the error goes away.
I would expect the model to be found.
An error indicating the model is not found.
Target: /Users/alexhaines/Projects/TestApp
OmniSharp server started with Mono 6.4.0.
Path: /Users/alexhaines/.vscode/extensions/ms-dotnettools.csharp-1.21.18/.omnisharp/1.35.1/omnisharp/OmniSharp.exe
PID: 24069
[info]: OmniSharp.Stdio.Host
Starting OmniSharp on MacOS 10.15.4 (x64)
DotNetPath set to dotnet
Located 2 MSBuild instance(s)
1: Mono 16.4 - "/Library/Frameworks/Mono.framework/Versions/6.4.0/lib/mono/msbuild/Current/bin"
2: StandAlone 16.4 - "/Users/alexhaines/.vscode/extensions/ms-dotnettools.csharp-1.21.18/.omnisharp/1.35.1/omnisharp/.msbuild/Current/Bin"
Registered MSBuild instance: Mono 16.4 - "/Library/Frameworks/Mono.framework/Versions/6.4.0/lib/mono/msbuild/Current/bin"
CscToolExe = csc.exe
CscToolPath = /Users/alexhaines/.vscode/extensions/ms-dotnettools.csharp-1.21.18/.omnisharp/1.35.1/omnisharp/.msbuild/Current/Bin/Roslyn
Detecting Cake files in '/Users/alexhaines/Projects/TestApp'.
Could not find any Cake files
No solution files found in '/Users/alexhaines/Projects/TestApp'
Queue project update for '/Users/alexhaines/Projects/TestApp/TestApp.csproj'
Detecting CSX files in '/Users/alexhaines/Projects/TestApp'.
Could not find any CSX files
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
Loading project: /Users/alexhaines/Projects/TestApp/TestApp.csproj
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
Configuration finished.
Omnisharp server running using Stdio at location '/Users/alexhaines/Projects/TestApp' on host 24044.
Successfully loaded project file '/Users/alexhaines/Projects/TestApp/TestApp.csproj'.
Adding project '/Users/alexhaines/Projects/TestApp/TestApp.csproj'
Update project: TestApp
VSCode version: 1.45.1
C# Extension: 1.21.18
Mono Information
OmniSharp using global mono :6.4.0
Dotnet Information
.NET Core SDK (reflecting any global.json):
Version: 3.1.100
Commit: cd82f021f4
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /usr/local/share/dotnet/sdk/3.1.100/
Host (useful for support):
Version: 3.1.0
Commit: 65f04fb6db
.NET Core SDKs installed:
2.2.101 [/usr/local/share/dotnet/sdk]
2.2.300 [/usr/local/share/dotnet/sdk]
3.0.101 [/usr/local/share/dotnet/sdk]
3.1.100 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Visual Studio Code Extensions
|Extension|Author|Version|
|---|---|---|
|csharp|ms-dotnettools|1.21.18|;
@NTaylorMullen does this look familiar?
@aseniah you poor soul lol the fact you drilled down into the exact problem really really helped. I've created a PR to fix the problem:
So sorry for the face palm worthy bug! 🤦♂️
https://github.com/dotnet/aspnetcore-tooling/pull/1959
Most helpful comment
@aseniah you poor soul lol the fact you drilled down into the exact problem really really helped. I've created a PR to fix the problem:
So sorry for the face palm worthy bug! 🤦♂️
https://github.com/dotnet/aspnetcore-tooling/pull/1959