dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.19k stars 9.93k forks source link

Crash on Attempted Set of <input /> Element "bind" Attribute #15929

Closed TheFanatr closed 4 years ago

TheFanatr commented 6 years ago

Attempting to set Blazor "bind" Attribute on Element Hangs and Crashes Visual Studio

a brief video showcasing this bug a brief video showcasing this bug

Explanation

Essentially, in this specific case, in an <input /> element, typing bind=@ in at the end of the tag will cause Visual Studio 2017 to crash. I have the latest version of both it and the Blazor language services extension, at 15.7.3 and 0.5.0-preview1-10320 respectively.

Behaviour Reproduction

The following is the source code needed to reproduce the bug.

TestPage.cshtml

@page  "/testpage"

<h1>Welcome to the Test Page!</h1>

<h2>Sample 1: LocalBrowserTodo</h2>

@if (TodoManager.Instance.Entries.Count > 0)
{
    <table style="width:100%">
        <thead>

            <tr>

                <th>Title</th>
                <th>Content</th>
                <th></th>
                <th></th>

            </tr>

        </thead>

        @foreach (TodoManager.TodoEntry entry in TodoManager.Instance.Entries)
        {
            <tr>

                @if (!entry.IsEditing)
                {
                    <th>@entry.Title</th>
                    <th>@entry.Content</th>

                }
                else
                {
                    <th><input value=@entry.Title/></th>
                    <th><input value=@entry.Content/></th>

                }
                <th><button type="button" onclick=@(() => entry.IsEditing = !entry.IsEditing)>@(entry.IsEditing ? "Stop" : "") Edit</button></th>
                <th><button type="button" onclick=@entry.Delete>Delete</button></th>

            </tr>
        }
    </table>

}
else
{
    <strong>Nothing to do!</strong>
}

<button type="button" onclick=@AddRandomTodo>Add @(TodoManager.Instance.Entries.Count > 0 ? "another" : "a") random one!</button>
<h4>Note that for now, the titles of the todo entries are just random double-precision values and the contents are just random integers.</h4>

@functions
{
static Random Random { get; } = new Random { };

void AddRandomTodo() => TodoManager.Instance.Entries.Add(new TodoManager.TodoEntry { Title = Random.NextDouble().ToString(), Content = Random.Next() });

}

TodoManager.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlazorTestApp.Client
{
    class TodoManager
    {
        internal class TodoEntry
        {
            static int InstanceCount { get; set; } = 0;

            internal int ID { get; } = InstanceCount++;

            internal string Title { get; set; } = String.Empty;

            internal object Content { get; set; } = String.Empty;

            internal bool Completed { get; set; } = false;

            internal bool IsEditing { get; set; } = false;

            internal void Delete() => Instance.Entries.Remove(this);
        }

        internal List<TodoEntry> Entries { get; } = new List<TodoEntry> { };

        internal TodoEntry this[int id] => Entries.Find(entry => entry.ID == id);

        internal void Reset() => Entries.Clear();

        internal static TodoManager Instance { get; } = new TodoManager { };
    }
}

Please ignore any implementation oddities, as project was just made to mess around with Blazor.

Metadata

Event Viewer Logs

The following is what Event Viewer had to say about the issue.

.NET Runtime

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException
   at System.Linq.Enumerable.Single[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at Microsoft.AspNetCore.Blazor.Razor.BindLoweringPass.GetAttributeContent(Microsoft.AspNetCore.Razor.Language.Intermediate.TagHelperPropertyIntermediateNode)
   at Microsoft.AspNetCore.Blazor.Razor.BindLoweringPass.RewriteUsage(Microsoft.AspNetCore.Razor.Language.Intermediate.IntermediateNode, Microsoft.AspNetCore.Razor.Language.Intermediate.TagHelperPropertyIntermediateNode)
   at Microsoft.AspNetCore.Blazor.Razor.BindLoweringPass.ExecuteCore(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument, Microsoft.AspNetCore.Razor.Language.Intermediate.DocumentIntermediateNode)
   at Microsoft.AspNetCore.Razor.Language.IntermediateNodePassBase.Execute(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument, Microsoft.AspNetCore.Razor.Language.Intermediate.DocumentIntermediateNode)
   at Microsoft.AspNetCore.Razor.Language.DefaultRazorOptimizationPhase.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.DefaultRazorProjectEngine.ProcessCore(Microsoft.AspNetCore.Razor.Language.RazorCodeDocument)
   at Microsoft.AspNetCore.Razor.Language.RazorProjectEngine.ProcessDesignTime(Microsoft.AspNetCore.Razor.Language.RazorProjectItem)
   at Microsoft.VisualStudio.Editor.Razor.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()

Application Error

Faulting application name: devenv.exe, version: 15.7.27703.2026, time stamp: 0x5b0f5e36
Faulting module name: KERNELBASE.dll, version: 10.0.17134.1, time stamp: 0x149ab0fd
Exception code: 0xe0434352
Fault offset: 0x0010d722
Faulting process id: 0x6e54
Faulting application start time: 0x01d3fecf3951769e
Faulting application path: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report Id: 0f1bbcfb-83a4-4b0c-acf2-7dc587d6ff06
Faulting package full name: 
Faulting package-relative application ID: 

Installed Extensions List

The following is a list of all the extensions I have installed in my configuration of Visual Studio, in case it applies, but I suspect it will not.

{
  "id": "3866550c-4a12-48e9-8f27-414aab12731f",
  "name": "My Visual Studio extensions",
  "description": "A collection of my Visual Studio extensions",
  "version": "1.0",
  "extensions": [
    {
      "name": "Azure Functions and Web Jobs Tools",
      "vsixId": "Microsoft.VisualStudio.Web.AzureFunctions"
    },
    {
      "name": "Razor Language Services",
      "vsixId": "Microsoft.VisualStudio.RazorExtension"
    },
    {
      "name": "Visual Studio IntelliCode - Preview",
      "vsixId": "IntelliCode.VSIX.598224b2-b987-401b-8509-f568d0c0b946"
    },
    {
      "name": "NP.XAMLIntellisenseExtensionForVS2017",
      "vsixId": "NP.XAMLIntellisenseExtensionForVS2017.9c3d92c1-cbae-4738-a2f2-1e48eab3f15a"
    },
    {
      "name": "Command Explorer",
      "vsixId": "1a973c52-a674-48d8-a276-65ddab1ac598"
    },
    {
      "name": "KnownMonikers Explorer",
      "vsixId": "c38f3512-4653-4d97-a4c5-860a425209f5"
    },
    {
      "name": "VS Live Share - Preview",
      "vsixId": "Microsoft.VisualStudio.LiveShare"
    },
    {
      "name": "Extensibility Tools",
      "vsixId": "f8330d54-0469-43a7-8fc0-7f19febeb897"
    },
    {
      "name": "Code Cracker for C#",
      "vsixId": "CodeCracker.Vsix..5b99e64c-1418-4a06-990c-fd4cf01f4f63"
    },
    {
      "name": "StatusInfo",
      "vsixId": "72581eb6-4dcd-4b8f-9add-c4257d4fb9d7"
    },
    {
      "name": "Stack Overflow Quick Launch Search Provider",
      "vsixId": "63E411F1-E531-44E8-8689-16B34600CF25"
    },
    {
      "name": "File Differ",
      "vsixId": "ea5c68d6-cdae-4e79-bd46-2a39e95bb256"
    },
    {
      "name": ".ignore",
      "vsixId": "7ac24965-ea21-4108-9cac-6e46394aaaef"
    },
    {
      "name": "Add New File",
      "vsixId": "2E78AA18-E864-4FBB-B8C8-6186FC865DB3"
    },
    {
      "name": "Unit Test Boilerplate Generator",
      "vsixId": "UnitTestBoilerplate.RandomEngy.ca0bb824-eb5a-41a8-ab39-3b81f03ba3fe"
    },
    {
      "name": ".NET Portability Analyzer",
      "vsixId": "55d15546-28ca-40dc-af23-dfa503e9c5fe"
    },
    {
      "name": "Markdown Editor",
      "vsixId": "9ca64947-e9ca-4543-bfb8-6cce9be19fd6"
    },
    {
      "name": "File Nesting",
      "vsixId": "6c799bc4-0d4c-4172-98bc-5d464b612dca"
    },
    {
      "name": "Select Next Occurrence",
      "vsixId": "NextOccurrence.b213c4e9-b96f-4f9d-b1d6-fa8bc7e9da21"
    },
    {
      "name": "File Icons",
      "vsixId": "3a7b4930-a5fb-46ec-a9b8-9610c8f953b8"
    },
    {
      "name": "Refactoring Essentials for Visual Studio 2017",
      "vsixId": "RefactoringEssentials.Vsix.cd27e59b-5c56-4238-8931-c9bb745a7a7f"
    },
    {
      "name": "Experimental Tools 2017",
      "vsixId": "fe00c281-eed0-4c6e-901b-d8b845c82e35"
    },
    {
      "name": "Open in Visual Studio Code",
      "vsixId": "e99dde0e-e023-410d-bc5d-3f76db71e3f0"
    },
    {
      "name": "Stack Trace Explorer",
      "vsixId": "Terrajobst.StackTraceExplorer.4995ed73-eaa4-4c4c-98fc-1e90df4aea6f"
    },
    {
      "name": "UnBlockDllExtension",
      "vsixId": "aee1ca98-a39a-4986-ba81-a36603ff6e02"
    },
    {
      "name": "BuildVision",
      "vsixId": "837c3c3b-8382-4839-9c9a-807b758a929f"
    },
    {
      "name": "Surround Selection",
      "vsixId": "4c807d55-9263-4ce0-9c1a-bfef58e96b02"
    },
    {
      "name": "Automatic Versions 1",
      "vsixId": "7f3f0c54-770a-4980-b3a0-5d9c4db90169"
    },
    {
      "name": "CodeMaid",
      "vsixId": "4c82e17d-927e-42d2-8460-b473ac7df316"
    },
    {
      "name": "ASP.NET Core Blazor Language Services",
      "vsixId": "Microsoft.VisualStudio.BlazorExtension"
    },
    {
      "name": "GitHub Extension for Visual Studio",
      "vsixId": "c3d3dc68-c977-411f-b3e8-03b0dccf7dfc"
    }
  ]
}

I do have some more data I could upload, but posting download links is shady, so I am avoiding it.

Thanks.

jiggyswift commented 6 years ago

Just confirming this happened to me in 0.4.0. I never got a Visual Studio crash in 0.3.0, but in 0.4.0 I got the same error, just types <input bind=@ and Visual Studio crashed. Tried again and it crashed again.

rynowak commented 6 years ago

This should be fixed in the dev branch