question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Razor Language Server suddenly fails with DirectoryNotFound exception after moving some files.

See original GitHub issue

Issue Description

Razor Language Server looks for files in directories no longer present and throws DirectoryNotFound exception. The location of the files is not referred to in any .csproj, and the project builds and runs just fine.

Environment data

dotnet --info output:

.NET Core SDK (reflecting any global.json):
 Version:   3.1.300
 Commit:    b2475c1295

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.300/

Host (useful for support):
  Version: 3.1.4
  Commit:  0c2e69caa6

.NET Core SDKs installed:
  3.1.300 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.1.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

VS Code version: 1.45.1

C# Extension version: 1.22.0

OmniSharp log — Razor

Unhandled exception. System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/nikolaidamm/Repos/Work/BusinessUMLCreator/src/UI/BlazorSVG/Debugging/DebugGrid.razor'.
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Microsoft.AspNetCore.Razor.LanguageServer.Common.DefaultRemoteTextLoaderFactory.RemoteTextLoader.LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer.Common/DefaultRemoteTextLoaderFactory.cs:line 62
   at Microsoft.CodeAnalysis.Razor.ProjectSystem.DefaultProjectSnapshotManager.<>c__DisplayClass17_0.<DocumentAdded>b__0() in /_/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotManager.cs:line 152
   at Microsoft.CodeAnalysis.Razor.ProjectSystem.DocumentState.GetTextVersionAsync() in /_/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentState.cs:line 131
   at Microsoft.CodeAnalysis.Razor.ProjectSystem.DocumentState.ComputedStateTracker.GetGeneratedOutputAndVersionCoreAsync(DefaultProjectSnapshot project, DocumentSnapshot document) in /_/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DocumentState.cs:line 352
   at Microsoft.CodeAnalysis.Razor.ProjectSystem.DefaultDocumentSnapshot.GetGeneratedOutputAsync() in /_/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultDocumentSnapshot.cs:line 63
   at Microsoft.AspNetCore.Razor.LanguageServer.RazorDiagnosticsPublisher.PublishDiagnosticsAsync(DocumentSnapshot document) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDiagnosticsPublisher.cs:line 161
   at Microsoft.AspNetCore.Razor.LanguageServer.RazorDiagnosticsPublisher.WorkTimer_Tick(Object state) in /_/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RazorDiagnosticsPublisher.cs:line 204
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
[Error - 2:21:35 PM] Connection to server got closed. Server will not be restarted.

Steps to reproduce

  1. Open VSCode
  2. Open workspace with the project that fails
  3. Wait
  4. Razor Language Server fails five times and closes.

I can add the directories and empty files, after which the problem will disappear, but if I delete them again, the problem resurfaces immediately.

Expected behavior

I’d expect the language server not to look for those files after I have moved them. It seems some data is cached, and I can’t figure out how to clean it, so it looks at the project structure as is, and not as was.

Actual behavior

It looks for files even though I have moved them, and fails when it can’t find them.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
devantlercommented, Jun 20, 2020

The problem still happens way too often. It seems to be triggered by changing branches. It, for example, occurs when I switch from a branch that has one specific folder structure to one with changes to that folder structure.

The result is still the error above as the Razor Language Server fails to find the folder/file, as it has changed location on the new branch.

A way to reset the Language Server to its initial state (the one it has when opening a “brand new” project) would be helpful until this has been stabilized.

1reaction
devantlercommented, Jun 4, 2020

Deleting the project from disk, and cloning it from GitHub fixed the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DirectoryNotFoundException While Trying To Uplode Any File ...
I am Trying To make A form In Ef core Razor pages where I have to upload Salary slip and save it in...
Read more >
Razor editor crashing (intellisense stops working, false ...
In certain files, razor server will simply stop working. Output panel are showing these exceptions: Warning: OmniSharp.Extensions.LanguageServer.Server.
Read more >
System.IO.DirectoryNotFoundException by File.Move
Just a quick question (I hope): When I use File.Move it gives me an error:
Read more >
Language Server Protocol Specification - 3.17
This document describes the 3.17.x version of the language server protocol. An implementation for node of the 3.17.x version of the protocol can...
Read more >
Common .NET Software Errors and How to Fix Them - Stackify
To fix/avoid this error: Build null checking into the code and set default values. Use Debug.Assert to catch the problem before the exception ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found