Skip to content

Creating new Blazor Client Side app -> Open .razor file can result in an exception #12585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NTaylorMullen opened this issue Jul 25, 2019 · 7 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed External This is an issue in a component not contained in this repository. It is open for tracking purposes.

Comments

@NTaylorMullen
Copy link

NTaylorMullen commented Jul 25, 2019

Just found that after creating a Blazor client side application you can occasionally get:


Error encountered from project 'C:\Users\nimullen.REDMOND\source\repos\Repro\Repro\.\Repro.csproj': System.InvalidOperationException: The file 'C:/Users/nimullen.REDMOND/source/repos/Repro/Repro/Shared/MainLayout.razor' is not a descendent of the base path 'C:/Users/nimullen.REDMOND/source/repos/Repro/Repro/.'.   at Microsoft.AspNetCore.Razor.Language.DefaultRazorProjectFileSystem.GetItem(String path, String fileKind)   at 
Microsoft.CodeAnalysis.Razor.ProjectSystem.DocumentState.GetImportsCore(DefaultProjectSnapshot project)   at 
Microsoft.CodeAnalysis.Razor.ProjectSystem.DefaultDocumentSnapshot.GetImports()   at 
Microsoft.CodeAnalysis.Razor.ProjectSystem.DocumentState.ComputedStateTracker.<GetImportsAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)   at 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)   at 
Microsoft.CodeAnalysis.Razor.ProjectSystem.DocumentState.ComputedStateTracker.<GetGeneratedOutputAndVersionCoreAsync>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)   at 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)   at Microsoft.CodeAnalysis.Razor.ProjectSystem.DefaultDocumentSnapshot.<GetGeneratedOutputAsync>d__20.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)   at 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)   at Microsoft.CodeAnalysis.Razor.BackgroundDocumentGenerator.<ProcessDocument>d__44.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at 
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)   at 
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)   at Microsoft.CodeAnalysis.Razor.BackgroundDocumentGenerator.<TimerTick>d__48.MoveNext()
--



I'm having an extremely hard time reproducing the issue. That being said this is most likely a VS issue since IVsHierarchy is obviously providing us a bogus project path: https://github.com/aspnet/AspNetCore-Tooling/blob/master/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultTextBufferProjectService.cs#L67-L79

or the project system is providing us a bogus project path: https://github.com/aspnet/AspNetCore-Tooling/blob/ff1a749559a093b2f5bfce48da9597995f27c280/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/DefaultRazorProjectHost.cs#L107

@BillHiebert is there a known issue on the project system side of the world where UnconfiguredProject can have a funky project path when the project is in the midst of loading?

Here's where I reprod it (ignore the null ref exception, that's a WTE issue), you can see it mentioned in the activity logs:
image

@NTaylorMullen NTaylorMullen added bug This issue describes a behavior which is not expected - a bug. External This is an issue in a component not contained in this repository. It is open for tracking purposes. area-blazor Includes: Blazor, Razor Components labels Jul 25, 2019
@NTaylorMullen NTaylorMullen self-assigned this Jul 25, 2019
@BillHiebert
Copy link

@NTaylorMullen I assume it is the extra .\ that is causing the issue? I wonder if the template is creating the project with this path. Would calling Path.GetFullPath() normalize these?

@NTaylorMullen
Copy link
Author

@BillHiebert yup, the extra .. Path.GetFullPath would probably normalize but I wouldn't imagine that'd be necessary since we haven't run into this before. Is this new behavior the result of something recent and expected? I imagine we wouldn't be the only ones impacted.

@BillHiebert
Copy link

@phenning could a template change have caused this?

@phenning
Copy link
Contributor

This looks like it was a result of combining the Blazor template down into one template. When it creates a non-hosted version of the template, it renames the Client\client.csproj file to .\client.csproj and returns that relative path via primaryOutputs.

I have a fix ready for the VS side. I did notice that if you close the solution and reopen, everything is fine, even though the sln file still has the .\ segment in the path.

@NTaylorMullen
Copy link
Author

NTaylorMullen commented Jul 25, 2019

This looks like it was a result of combining the Blazor template down into one template. When it creates a non-hosted version of the template, it renames the Client\client.csproj file to .\client.csproj and returns that relative path via primaryOutputs.

I have a fix ready for the VS side. I did notice that if you close the solution and reopen, everything is fine, even though the sln file still has the .\ segment in the path.

Awesome, @phenning could you include me in those VS side changes so I can forward along to those impacted?

Also, I imagine that fix would make it in for 3.0.0-preview8 / VS16.3-preview2 correct?

@NTaylorMullen NTaylorMullen added this to the 3.0.0-preview8 milestone Jul 25, 2019
@phenning
Copy link
Contributor

@NTaylorMullen Added you to the PR in the WebTools repo.

And yes, this will make 16.3-preview2

@NTaylorMullen NTaylorMullen added the Done This issue has been fixed label Jul 25, 2019
@NTaylorMullen
Copy link
Author

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed External This is an issue in a component not contained in this repository. It is open for tracking purposes.
Projects
None yet
Development

No branches or pull requests

3 participants