Open
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
If any kind of exception is thrown during (the auto-generated) BuildRenderTree execution, only the type of exception is logged and not which source line it occurred in, so it's impossible to know which line caused it. e.g.
System.NullReferenceException: Object reference not set to an instance of an object. at BlazorRenderErrros.Components.Pages.Home.BuildRenderTree(RenderTreeBuilder __builder) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
Expected Behavior
It would be incredibly helpful if;
- VS could break on the exception in the original source .razor file
- Line numbers of the original .razor source file where the exception happened were included in the stack trace
Steps To Reproduce
Running the example project will demonstrate.
The deliberate error is in Home.razor - line 7 - where is tries to render the length of the string which is null;
<h2>Length is @someString.Length</h2>
Welcome to your new app.
@code{
string? someString = null;
}
This is a trivial example to see what's wrong, but with large, complicated paged its not easy to find the cause.
The exception in the browser is
System.NullReferenceException: Object reference not set to an instance of an object. at BlazorRenderErrros.Components.Pages.Home.BuildRenderTree(RenderTreeBuilder __builder) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
In the included generated files (Components_Pages_Home_razor.g.cs) it records that it's from line 7 so it has this information;
__builder.AddContent(7,
#nullable restore
#line (7,16)-(7,33) "D:\source\BlazorRenderErrros\BlazorRenderErrros\Components\Pages\Home.razor"
someString.Length
#line default
Exceptions (if any)
No response
.NET Version
9.0.200
Anything else?
VS Info
Microsoft Visual Studio Enterprise 2022
Version 17.12.4
VisualStudio.17.Release/17.12.4+35707.178
Microsoft .NET Framework
Version 4.8.09032
Installed Version: Enterprise
ASP.NET and Web Tools 17.12.178.10385
ASP.NET and Web Tools
Azure App Service Tools v3.0.0 17.12.178.10385
Azure App Service Tools v3.0.0
Azure Functions and Web Jobs Tools 17.12.178.10385
Azure Functions and Web Jobs Tools
C# Tools 4.12.0-3.24631.1+da7c6c4257b2f661024b9a506773372a09023eee
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
GitHub Copilot 17.12.53.23981
GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.
Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
NuGet Package Manager 6.12.3
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
Razor (ASP.NET Core) 17.12.3.2457601+b5256abf658352440e61aa1372bbc0798e9ceb7d
Provides languages services for ASP.NET Core Razor.
SQL Server Data Tools 17.12.83.3
Microsoft SQL Server Data Tools
TypeScript Tools 17.0.30918.2001
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 4.12.0-3.24631.1+da7c6c4257b2f661024b9a506773372a09023eee
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 17.12.0-beta.24501.1+19610c0b654766eec49d044cb97ca6eaa2a63d16
Microsoft Visual F# Tools
Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.
Activity