Skip to content

Formatting a Razor page using Ctrl+K, D always fails with an exception that requests 'please report this issue' #12635

@vsfeedback

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


Attempting to reformat a Razor page using Ctrl+K, D always fails with this exception below. I tried to upload the source file, but .cshtml is a disallowed extension, so, ehhm, yeah...

StreamJsonRpc.RemoteInvocationException: Ran out of formatted lines while trying to process formatted changes after 137 lines. Abandoning further formatting to not corrupt the source file, please report this issue.
   at StreamJsonRpc.JsonRpc. <InvokeCoreAsync>d__171`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1. <TryInvokeAsync>d__18`1.MoveNext()
RPC server exception:
System.InvalidOperationException: Ran out of formatted lines while trying to process formatted changes after 137 lines. Abandoning further formatting to not corrupt the source file, please report this issue.
      at Microsoft.CodeAnalysis.Remote.Razor.ThrowingErrorLoggerProvider.Logger.Log(LogLevel logLevel, String message, Exception exception)
      at Microsoft.CodeAnalysis.Razor.Logging.AbstractLoggerFactory.AggregateLogger.Log(LogLevel logLevel, String message, Exception exception)
      at Microsoft.CodeAnalysis.Razor.Logging.ILoggerExtensions.LogError(ILogger logger, ErrorLogMessageInterpolatedStringHandler& message)
      at Microsoft.CodeAnalysis.Razor.Formatting.CSharpFormattingPass.ExecuteAsync(FormattingContext context, ImmutableArray`1 changes, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Razor.Formatting.RazorFormattingService.GetDocumentFormattingChangesAsync(DocumentContext documentContext, ImmutableArray`1 htmlChanges, Nullable`1 range, RazorFormattingOptions options, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass7_0`1. <<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspaceManager.RunServiceAsync[T](ServiceBrokerClient client, Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)

Original Comments

David Wengier [MSFT] on 05/01/2026, 11:33 AM:

Thanks for logging this issue! For these cases, we have some extra logging that you can enable that will capture all of the information to allow us to reproduce and fix the issue in a test. If you can turn on the extra formatting logging, run the format operation again, and upload the results to this issue, we’ll be able to fix the problem ASAP. The extra logging information is in this doc: https://github.com/dotnet/razor/blob/main/docs/Formatting.md#turn-on-formatting-logging

We really appreciate you taking the time to do this, and help make the product better for everyone.

Michiel de Bruijn on 05/01/2026, 05:26 PM:

I found a minimal repro case just now:

This works as expected:

@page
@{
	Func<(bool b1, bool b2), object> o1 = @<text>
		<div></div>
	</text>;
}

But this triggers the exception:

@page
@{
	Func<(bool b1, bool b2), object> o1 = @<text>
		<div></div>
	</text>;
	Func<(bool b1, bool b2), object> o2 = @<text>
		<div></div>
	</text>;
}

(In fact, you don’t even need the @page, just leaving that in to give some context on the location of the code, although that doesn’t even seem to matter too much)

unknown_temp on 05/01/2026, 05:47 PM:

Thanks Michiel de Bruijn thats all I need! I’m going to move this over to our GitHub repo and will fix it. Thanks again for the report and the repro example.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions