Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Razor editor crash when typing @namespace directive line #1268

Closed
DamianEdwards opened this issue Apr 28, 2017 · 12 comments
Closed

Razor editor crash when typing @namespace directive line #1268

DamianEdwards opened this issue Apr 28, 2017 · 12 comments
Assignees

Comments

@DamianEdwards
Copy link
Member

Using VS 2017 15.3 d15prerel 26427.6

Was adding @namespace RazorPagesSample.Pages.Blah to an existing page by typing it in manually in the editor, resulted in a crash. Pasting the complete line in worked OK.

@DamianEdwards
Copy link
Member Author

@rynowak @NTaylorMullen

@rynowak
Copy link
Member

rynowak commented Apr 28, 2017

d15prerel 26421.06 had our earlier fix for the parsing of @page so this definitely is a new issue.

@DamianEdwards
Copy link
Member Author

Stack trace:

System.Core.dll!System.Linq.Enumerable.First<Microsoft.AspNetCore.Razor.Language.Intermediate.DirectiveTokenIRNode>(System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Razor.Language.Intermediate.DirectiveTokenIRNode> source)	Unknown
 	Microsoft.AspNetCore.Mvc.Razor.Extensions.dll!Microsoft.AspNetCore.Mvc.Razor.Extensions.NamespaceDirective.TryComputeNamespace(string source, Microsoft.AspNetCore.Razor.Language.Intermediate.DirectiveIRNode directive, out string namespace)	Unknown
 	Microsoft.AspNetCore.Mvc.Razor.Extensions.dll!Microsoft.AspNetCore.Mvc.Razor.Extensions.NamespaceDirective.Pass.ExecuteCore(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument, Microsoft.AspNetCore.Razor.Language.Intermediate.DocumentIRNode irDocument)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.RazorIRPassBase.Execute(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument, Microsoft.AspNetCore.Razor.Language.Intermediate.DocumentIRNode irDocument)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.DefaultRazorDirectiveClassifierPhase.ExecuteCore(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.Execute(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument document)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine.GenerateCode(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.Legacy.BackgroundParser.BackgroundThread.ParseChange(Microsoft.AspNetCore.Razor.Language.Legacy.ITextBuffer buffer, System.Threading.CancellationToken token)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.Legacy.BackgroundParser.BackgroundThread.WorkerLoop()	Unknown
 	mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)	Unknown
 	mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()	Unknown

@rynowak
Copy link
Member

rynowak commented Apr 28, 2017

LOL I was about to post the same. Here's mine:

>	System.Core.dll!System.Linq.Enumerable.First<Microsoft.AspNetCore.Razor.Language.Intermediate.DirectiveTokenIRNode>(System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Razor.Language.Intermediate.DirectiveTokenIRNode> source)	Unknown
 	Microsoft.AspNetCore.Mvc.Razor.Extensions.dll!Microsoft.AspNetCore.Mvc.Razor.Extensions.NamespaceDirective.TryComputeNamespace(string source, Microsoft.AspNetCore.Razor.Language.Intermediate.DirectiveIRNode directive, out string namespace)	Unknown
 	Microsoft.AspNetCore.Mvc.Razor.Extensions.dll!Microsoft.AspNetCore.Mvc.Razor.Extensions.NamespaceDirective.Pass.ExecuteCore(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument, Microsoft.AspNetCore.Razor.Language.Intermediate.DocumentIRNode irDocument)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.RazorIRPassBase.Execute(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument, Microsoft.AspNetCore.Razor.Language.Intermediate.DocumentIRNode irDocument)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.DefaultRazorDirectiveClassifierPhase.ExecuteCore(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.Execute(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument document)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine.GenerateCode(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument codeDocument)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.Legacy.BackgroundParser.BackgroundThread.ParseChange(Microsoft.AspNetCore.Razor.Language.Legacy.ITextBuffer buffer, System.Threading.CancellationToken token)	Unknown
 	Microsoft.AspNetCore.Razor.Language.dll!Microsoft.AspNetCore.Razor.Language.Legacy.BackgroundParser.BackgroundThread.WorkerLoop()	Unknown
 	mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	Unknown
 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)	Unknown
 	mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()	Unknown

@rynowak
Copy link
Member

rynowak commented Apr 28, 2017

The fix is here: https://github.com/aspnet/Razor/blob/dev/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/NamespaceDirective.cs#L88 we need to be tolerant of invalid/incomplete parses.

@rynowak rynowak added this to the 2.0.0-preview1 milestone Apr 28, 2017
NTaylorMullen added a commit that referenced this issue Apr 29, 2017
- This involved not using the `First()` method when reading the directives tokens.
- Added two tests to validate an empty directive token and a missed directive token for the `@namespace` directive.

#1268
NTaylorMullen added a commit that referenced this issue Apr 29, 2017
- This involved not using the `First()` method when reading the directives tokens.
- Added two tests to validate an empty directive token and a missed directive token for the `@namespace` directive.

#1268
@NTaylorMullen
Copy link
Member

86beea4

@DamianEdwards
Copy link
Member Author

I don't see this fix in 2.0.0-preview1, only in dev...

@rynowak
Copy link
Member

rynowak commented May 3, 2017

Our stabilization branch for 15.3P1 is https://github.com/aspnet/Razor/tree/preview-1/stabilization We're not mixing in any general 2.0.0-preview1 changes with VS work unless there's a good reason.

We could merge this to preview1 if we want just for safety, but I'm not aware of any runtime impact

@DamianEdwards
Copy link
Member Author

Ok thanks, whatever you guys think is the right thing, just enumerating all the loose ends 😄

@analogrelay
Copy link
Contributor

analogrelay commented May 30, 2017

I'm getting a different error with the same repro:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
   at Microsoft.AspNetCore.Razor.Language.Legacy.CSharpCodeParser.HandleDirective(Microsoft.AspNetCore.Razor.Language.DirectiveDescriptor)
   at Microsoft.AspNetCore.Razor.Language.Legacy.CSharpCodeParser+<>c__DisplayClass93_0.<SetupDirectives>b__0()
   at Microsoft.AspNetCore.Razor.Language.Legacy.CSharpCodeParser.AfterTransition()
   at Microsoft.AspNetCore.Razor.Language.Legacy.CSharpCodeParser.AtTransition(Microsoft.AspNetCore.Razor.Language.Legacy.CSharpSymbol)
   at Microsoft.AspNetCore.Razor.Language.Legacy.CSharpCodeParser.ParseBlock()
   at Microsoft.AspNetCore.Razor.Language.Legacy.HtmlMarkupParser.OtherParserBlock()
   at Microsoft.AspNetCore.Razor.Language.Legacy.HtmlMarkupParser.SkipToAndParseCode(System.Func`2<Microsoft.AspNetCore.Razor.Language.Legacy.HtmlSymbol,Boolean>)
   at Microsoft.AspNetCore.Razor.Language.Legacy.HtmlMarkupParser.SkipToAndParseCode(Microsoft.AspNetCore.Razor.Language.Legacy.HtmlSymbolType)
   at Microsoft.AspNetCore.Razor.Language.Legacy.HtmlMarkupParser.ParseDocument()
   at Microsoft.AspNetCore.Razor.Language.Legacy.RazorParser.Parse(Microsoft.AspNetCore.Razor.Language.RazorSourceDocument)
   at Microsoft.AspNetCore.Razor.Language.RazorSyntaxTree.Parse(Microsoft.AspNetCore.Razor.Language.RazorSourceDocument, Microsoft.AspNetCore.Razor.Language.RazorParserOptions)
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorParsingPhase.ExecuteCore(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument)
   at Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.Execute(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument)
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument)
   at Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine.GenerateCode(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument)
   at Microsoft.AspNetCore.Razor.Language.Legacy.BackgroundParser+BackgroundThread.ParseChange(Microsoft.AspNetCore.Razor.Language.Legacy.ITextBuffer, System.Threading.CancellationToken)
   at Microsoft.AspNetCore.Razor.Language.Legacy.BackgroundParser+BackgroundThread.WorkerLoop()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

It occurs when typing @namespace in the src/Hubbup.Web/Pages/_ViewImports.cshtml file in the anurse/namespace-directive-crash branch of https://github.com/anurse/ProjectKIssueList

razor-crash
(To clarify, despite the GIF showing a _PageImports.cshtml file, I did try and repro the error in _ViewImports.cshtml)

VS: 15.3.0 Preview 1.0 [26526.1.d15rel]

@analogrelay analogrelay reopened this May 30, 2017
@NTaylorMullen
Copy link
Member

Investigating

@NTaylorMullen
Copy link
Member

@anurse I've filed a separate issue for this: #1393. Good find though!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants