Skip to content

VSCode: CodeLens references numbers did not load and the output window contain error "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object." when doing the Razor refactoring #4318

@NTaylorMullen

Description

@NTaylorMullen

Azure DevOps work item: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1284417

Testcases Affected

[6.0] SimpleWebAppRazorEditingWithVSCode
[6.0] SimpleBlazorRazorEditingWithVSCode

Platform

  • Windows
  • macOS
  • Linux

Repro Steps

  1. Create an MVC project and open via VS Code:
md MVC
cd MVC
dotnet new mvc
code .
  1. Go to https://github.com/OmniSharp/omnisharp-vscode/releasesinstall the latest csharp-1.23.10-lsp-beta.vsix.
  2. Open Pages/Shared/_Layout.cshtml
  3. Type "@add" and verify the intellisense list. Select "addTagHelper", then type "*, Microsoft.AspNetCore.Mvc.TagsHelpers" following it. Save the change.
  4. In VS Code, using CTRL + ~ to open up TERMINAL window, type the following code.
'namespace MVC // Or Razor
{
    public class CustomTagHelper
    {
    }
}' | Out-File CustomTagHelper.cs
  1. In CustomTagHelper.cs, type ": TagHelper" following the class. And then select "using Microsoft.AspNetCore.Razor.TagHelpers" through the Quick Actions
  2. In _Layout.cshtml, type "@addTagHelper *, MVC
  3. Open Program.cs, then enter the code: public interface ICheese {} above public class Program and save
  4. Edit Index.cshtml to include the following at the bottom:
@{ var x = typeof(Program); }
@functions {
 public class Cheddar : ICheese {}
}
  1. Save and close Index.cshtml
  2. Close all instances of VSCode and re-open this project.
  3. go to the program.cs file

Note:

  1. It works well on 5.0 Project
  2. It works well on 6.0 Preview 1

Actual Result

CodeLens references numbers did not load and the output window contain error "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object."
image

Error Log

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.

at OmniSharp.Helpers.LocationExtensions.<>c__DisplayClass0_0.b__3(Document d) in D:\a\1\s\src\OmniSharp.Roslyn.CSharp\Helpers\LocationExtensions.cs:line 45

at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source, Func2 predicate)

at OmniSharp.Helpers.LocationExtensions.g__GetSourceText|0_0(Location location, IEnumerable`1 documents, Boolean hasMappedPath) in D:\a\1\s\src\OmniSharp.Roslyn.CSharp\Helpers\LocationExtensions.cs:line 45

at OmniSharp.Helpers.LocationExtensions.GetQuickFix(Location location, OmniSharpWorkspace workspace) in D:\a\1\s\src\OmniSharp.Roslyn.CSharp\Helpers\LocationExtensions.cs:line 19

at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()

at System.Linq.Enumerable.d__64`1.MoveNext()

at System.Linq.Buffer1..ctor(IEnumerable1 source)

at System.Linq.OrderedEnumerable`1.d__1.MoveNext()

at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)

at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)

at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)

at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)

at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)

at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)

at OmniSharp.Protocol.Packet.ToString() in D:\a\1\s\src\OmniSharp.Host\Protocol\Packet.cs:line 22

at System.IO.TextWriter.WriteLine(Object value)

at System.IO.TextWriter.SyncTextWriter.WriteLine(Object value)

at OmniSharp.Services.SharedTextWriter.ProcessWriteQueue() in D:\a\1\s\src\OmniSharp.Host\Services\SharedTextWriter.cs:line 48

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions