dotnet/roslyn
View on GitHubEE does not parse format specifiers when compiling assignments
Open
#60,639 opened on Apr 7, 2022
Area-InteractiveBughelp wanted
Repository metrics
- Stars
- (20,414 stars)
- PR merge metrics
- (Avg merge 6d 17h) (256 merged PRs in 30d)
Description
Version Used: VS 17.3.0 Preview 1.0 [32405.266.main]
Steps to Reproduce:
- Create a new .NET 6 console app:
for (int i = 50; i < 60; ++i)
{
Debugger.Break();
}
- Evaluate the following in the watch window:
i, d
- Attempt to edit value
Expected
i has the new value..
Actual

Metadata When modifying the value of the variable, the debugger evaluates the expression with IDkmClrExpressionCompiler.CompileAssignment, which Roslyn does not clean up formatters when compiling expression.Text with ParseAssignemnt:
> Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator.ExpressionCompiler.dll!Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator.SyntaxHelpers.ParseAssignment(string target, string expr, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) Line 76 C#
Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator.ExpressionCompiler.dll!Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator.EvaluationContext.CompileAssignment(string target, string expr, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ExpressionEvaluator.Alias> aliases, Microsoft.CodeAnalysis.DiagnosticBag diagnostics, out Microsoft.CodeAnalysis.ExpressionEvaluator.ResultProperties resultProperties, Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData) Line 356 C#
Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.dll!Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.Microsoft.VisualStudio.Debugger.ComponentInterfaces.IDkmClrExpressionCompiler.CompileAssignment.AnonymousMethod__1(Microsoft.CodeAnalysis.ExpressionEvaluator.EvaluationContextBase context, Microsoft.CodeAnalysis.DiagnosticBag diagnostics) Line 161 C#
Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.dll!Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.CompileWithRetry<Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.CompileExpressionResult>(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ExpressionEvaluator.MetadataBlock> metadataBlocks, Microsoft.CodeAnalysis.DiagnosticFormatter formatter, Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.CreateContextDelegate createContext, Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.CompileDelegate<Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.CompileExpressionResult> compile, Microsoft.CodeAnalysis.ExpressionEvaluator.DkmUtilities.GetMetadataBytesPtrFunction getMetaDataBytesPtr, out string errorMessage) Line 392 C#
Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.dll!Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.CompileWithRetry<Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.CompileExpressionResult>(Microsoft.VisualStudio.Debugger.Clr.DkmClrAppDomain appDomain, Microsoft.VisualStudio.Debugger.Clr.DkmClrRuntimeInstance runtimeInstance, Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.CreateContextDelegate createContext, Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.CompileDelegate<Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.CompileExpressionResult> compile, out string errorMessage) Line 364 C#
Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.dll!Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.Microsoft.VisualStudio.Debugger.ComponentInterfaces.IDkmClrExpressionCompiler.CompileAssignment(Microsoft.VisualStudio.Debugger.Evaluation.DkmLanguageExpression expression, Microsoft.VisualStudio.Debugger.Clr.DkmClrInstructionAddress instructionAddress, Microsoft.VisualStudio.Debugger.Evaluation.DkmEvaluationResult lValue, out string error, out Microsoft.VisualStudio.Debugger.Evaluation.ClrCompilation.DkmCompiledClrInspectionQuery result) Line 155 C#
Microsoft.VisualStudio.Debugger.Engine.dll!Microsoft.VisualStudio.Debugger.EntryPoint.IDkmClrExpressionCompiler_CompileAssignment(System.IntPtr pvClassInfo, System.IntPtr Expression, System.IntPtr InstructionAddress, System.IntPtr LValue, ref System.IntPtr Error, ref System.IntPtr Result) Unknown
When evaluating an expression to display the result, a different entrypoint is used, which parses any custom formatting as an expression.