Skip to content

Loading ASP.NET Razor project failed with problems '{ expected [razor] csharp(CS1514)' and '} expected [razor] csharp(CS1513)' #4677

@dandanmu

Description

@dandanmu

Environment data

dotnet --info output:

.NET SDK (reflecting any global.json):
Version: 6.0.100-preview.7.21369.19
Commit: cdbd475cb6

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/6.0.100-preview.7.21369.19/

Host (useful for support):
Version: 6.0.0-preview.7.21368.2
Commit: 8d3afa3a4a

.NET SDKs installed:
6.0.100-preview.7.21369.19 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.0-preview.7.21369.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.0-preview.7.21368.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

VS Code version: 1.58.2

C# Extension version: 1.23.14

OmniSharp log

OmniSharp server started.
Path: /Users/e2euser2/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.13/run
PID: 2766

Starting OmniSharp on MacOS 10.15.7 (x64)
info: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 1 MSBuild instance(s)
1: StandAlone 17.0.0 - "/Users/e2euser2/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.13/omnisharp/.msbuild/Current/Bin"
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
MSBUILD_EXE_PATH environment variable set to '/Users/e2euser2/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.13/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: StandAlone 17.0.0 - "/Users/e2euser2/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.13/omnisharp/.msbuild/Current/Bin"
CscToolExe = csc.exe
MSBuildToolsPath = /Users/e2euser2/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.13/omnisharp/.msbuild/Current/Bin
CscToolPath = /Users/e2euser2/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.13/omnisharp/.msbuild/Current/Bin/Roslyn
BypassFrameworkInstallChecks = true
MSBuildExtensionsPath = /Users/e2euser2/.vscode/extensions/ms-dotnettools.csharp-1.23.14/.omnisharp/1.37.13/omnisharp/.msbuild
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
info: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in '/Users/e2euser2/test3/razor'.
info: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
info: OmniSharp.MSBuild.ProjectSystem
No solution files found in '/Users/e2euser2/test3/razor'
info: OmniSharp.MSBuild.ProjectManager
Queue project update for '/Users/e2euser2/test3/razor/razor.csproj'
info: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in '/Users/e2euser2/test3/razor'.
info: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
info: OmniSharp.WorkspaceInitializer
Configuration finished.
info: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location '/Users/e2euser2/test3/razor' on host 2738.
info: OmniSharp.MSBuild.ProjectManager
Loading project: /Users/e2euser2/test3/razor/razor.csproj
info: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file '/Users/e2euser2/test3/razor/razor.csproj'.
info: OmniSharp.MSBuild.ProjectManager
Adding project '/Users/e2euser2/test3/razor/razor.csproj'
info: OmniSharp.MSBuild.ProjectManager
Update project: razor
Received response for /v2/getcodeactions but could not find request.

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at OmniSharp.Helpers.LocationExtensions+<>c.b__0_2 (Microsoft.CodeAnalysis.Document document) [0x00000] in <5d718b9165a845c1b3284ab2a4228fbc>:0
at System.Linq.Utilities+<>c__DisplayClass2_03[TSource,TMiddle,TResult].<CombineSelectors>b__0 (TSource x) [0x00012] in <17e8581c65f940ca8137dd67206f5dbd>:0 at System.Linq.Enumerable+SelectArrayIterator2[TSource,TResult].ToArray () [0x00012] in <17e8581c65f940ca8137dd67206f5dbd>:0
at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable1[T] source) [0x0001f] in <17e8581c65f940ca8137dd67206f5dbd>:0 at OmniSharp.Helpers.LocationExtensions.GetQuickFix (Microsoft.CodeAnalysis.Location location, OmniSharp.OmniSharpWorkspace workspace) [0x00128] in <5d718b9165a845c1b3284ab2a4228fbc>:0 at OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService+<>c__DisplayClass3_0.<Handle>b__2 (Microsoft.CodeAnalysis.Location l) [0x00000] in <5d718b9165a845c1b3284ab2a4228fbc>:0 at System.Linq.Enumerable+SelectEnumerableIterator2[TSource,TResult].MoveNext () [0x00048] in <17e8581c65f940ca8137dd67206f5dbd>:0
at System.Linq.Set1[TElement].UnionWith (System.Collections.Generic.IEnumerable1[T] other) [0x00018] in <17e8581c65f940ca8137dd67206f5dbd>:0
at System.Linq.Enumerable+DistinctIterator1[TSource].FillSet () [0x0000b] in <17e8581c65f940ca8137dd67206f5dbd>:0 at System.Linq.Enumerable+DistinctIterator1[TSource].ToArray () [0x00000] in <17e8581c65f940ca8137dd67206f5dbd>:0
at System.Linq.Buffer1[TElement]..ctor (System.Collections.Generic.IEnumerable1[T] source) [0x0000a] in <17e8581c65f940ca8137dd67206f5dbd>:0
at System.Linq.OrderedEnumerable1+<GetEnumerator>d__3[TElement].MoveNext () [0x0001e] in <17e8581c65f940ca8137dd67206f5dbd>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList (Newtonsoft.Json.JsonWriter writer, System.Collections.IEnumerable values, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000e1] in <2676a2da6edc420e890ed28aa4572ee5>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000d6] in <2676a2da6edc420e890ed28aa4572ee5>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x0008d] in <2676a2da6edc420e890ed28aa4572ee5>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000b2] in <2676a2da6edc420e890ed28aa4572ee5>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x0008d] in <2676a2da6edc420e890ed28aa4572ee5>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000b2] in <2676a2da6edc420e890ed28aa4572ee5>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00079] in <2676a2da6edc420e890ed28aa4572ee5>:0 at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x0023a] in <2676a2da6edc420e890ed28aa4572ee5>:0 at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0 at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00028] in <2676a2da6edc420e890ed28aa4572ee5>:0 at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x00007] in <2676a2da6edc420e890ed28aa4572ee5>:0 at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0 at OmniSharp.Protocol.Packet.ToString () [0x00000] in <9eeefa70512d40c69c79c801305ec785>:0 at System.IO.TextWriter.WriteLine (System.Object value) [0x00028] in <b18e5763ec3f41e68a8fe16d7f5e0bee>:0 at System.IO.TextWriter+SyncTextWriter.WriteLine (System.Object value) [0x00000] in <b18e5763ec3f41e68a8fe16d7f5e0bee>:0 at (wrapper synchronized) System.IO.TextWriter+SyncTextWriter.WriteLine(object) at OmniSharp.Services.SharedTextWriter.ProcessWriteQueue () [0x0001d] in <9eeefa70512d40c69c79c801305ec785>:0 at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00014] in <b18e5763ec3f41e68a8fe16d7f5e0bee>:0 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <b18e5763ec3f41e68a8fe16d7f5e0bee>:0 at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <b18e5763ec3f41e68a8fe16d7f5e0bee>:0 at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x0002b] in <b18e5763ec3f41e68a8fe16d7f5e0bee>:0 at System.Threading.ThreadHelper.ThreadStart () [0x00008] in <b18e5763ec3f41e68a8fe16d7f5e0bee>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object at OmniSharp.Helpers.LocationExtensions+<>c.<GetQuickFix>b__0_2 (Microsoft.CodeAnalysis.Document document) [0x00000] in <5d718b9165a845c1b3284ab2a4228fbc>:0 at System.Linq.Utilities+<>c__DisplayClass2_03[TSource,TMiddle,TResult].b__0 (TSource x) [0x00012] in <17e8581c65f940ca8137dd67206f5dbd>:0
at System.Linq.Enumerable+SelectArrayIterator2[TSource,TResult].ToArray () [0x00012] in <17e8581c65f940ca8137dd67206f5dbd>:0 at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable1[T] source) [0x0001f] in <17e8581c65f940ca8137dd67206f5dbd>:0
at OmniSharp.Helpers.LocationExtensions.GetQuickFix (Microsoft.CodeAnalysis.Location location, OmniSharp.OmniSharpWorkspace workspace) [0x00128] in <5d718b9165a845c1b3284ab2a4228fbc>:0
at OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService+<>c__DisplayClass3_0.b__2 (Microsoft.CodeAnalysis.Location l) [0x00000] in <5d718b9165a845c1b3284ab2a4228fbc>:0
at System.Linq.Enumerable+SelectEnumerableIterator2[TSource,TResult].MoveNext () [0x00048] in <17e8581c65f940ca8137dd67206f5dbd>:0 at System.Linq.Set1[TElement].UnionWith (System.Collections.Generic.IEnumerable1[T] other) [0x00018] in <17e8581c65f940ca8137dd67206f5dbd>:0 at System.Linq.Enumerable+DistinctIterator1[TSource].FillSet () [0x0000b] in <17e8581c65f940ca8137dd67206f5dbd>:0
at System.Linq.Enumerable+DistinctIterator1[TSource].ToArray () [0x00000] in <17e8581c65f940ca8137dd67206f5dbd>:0 at System.Linq.Buffer1[TElement]..ctor (System.Collections.Generic.IEnumerable1[T] source) [0x0000a] in <17e8581c65f940ca8137dd67206f5dbd>:0 at System.Linq.OrderedEnumerable1+d__3[TElement].MoveNext () [0x0001e] in <17e8581c65f940ca8137dd67206f5dbd>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList (Newtonsoft.Json.JsonWriter writer, System.Collections.IEnumerable values, Newtonsoft.Json.Serialization.JsonArrayContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000e1] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000d6] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x0008d] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000b2] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x0008d] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContract valueContract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x000b2] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00079] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x0023a] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00028] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x00007] in <2676a2da6edc420e890ed28aa4572ee5>:0
at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value) [0x00000] in <2676a2da6edc420e890ed28aa4572ee5>:0
at OmniSharp.Protocol.Packet.ToString () [0x00000] in <9eeefa70512d40c69c79c801305ec785>:0
at System.IO.TextWriter.WriteLine (System.Object value) [0x00028] in :0
at System.IO.TextWriter+SyncTextWriter.WriteLine (System.Object value) [0x00000] in :0
at (wrapper synchronized) System.IO.TextWriter+SyncTextWriter.WriteLine(object)
at OmniSharp.Services.SharedTextWriter.ProcessWriteQueue () [0x0001d] in <9eeefa70512d40c69c79c801305ec785>:0
at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00014] in :0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in :0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in :0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x0002b] in :0
at System.Threading.ThreadHelper.ThreadStart () [0x00008] in :0

Steps to reproduce

  1. Create a new ASP.NET Razor project by doing

    mkdir razor
    cd razor
    dotnet new razor
    
  2. Install VS code (if you have not already) https://code.visualstudio.com/Download

  3. Launch VSCode and install the C# extension.

  4. Install the 1.15 or later C# (by OmniSharp) Extention (View -> Extensions, then type OmniSharp, and click on ‘Install’)

  5. Use File -> Open Folder to open the razor folder you have created in step 1

Expected behavior

Razor can open with no problems.

Actual behavior

Problems appear after opening the razor.
MicrosoftTeams-image (13)
Note:

  1. Unit test project also repro this issue.
  2. This issue not occur with .NET 6 preview6 SDK installed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixedFixed and available in the stable version of C# Extension.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions