Skip to content

Format on type error: A format operation is being abandoned because it would introduce or remove one of more diagnostics. #12481

@Peter-Juhasz

Description

@Peter-Juhasz

VS 111206.111 (default preview features, so cohosting is on)

Minimal repro, type the closing brace } of else clause:

@page "/"

@if (true)
{
	<option value="@streetKind">@streetKind</option>
}
else {
	<input />
$$

@code {
	private string? streetKind;
}

Error:

StreamJsonRpc.RemoteInvocationException: A format operation is being abandoned because it would introduce or remove one of more diagnostics.
Diagnostics before:
Diagnostics after:
REDACTED.razor(5,31): Error RZ1003: A space or line break was encountered after the "@" character.  Only valid identifiers, keywords, comments, "(" and "{" are valid at the start of a code block and they must occur immediately following "@" with no space in between.

   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: A format operation is being abandoned because it would introduce or remove one of more diagnostics.
Diagnostics before:
Diagnostics after:
REDACTED.razor(5,31): Error RZ1003: A space or line break was encountered after the "@" character.  Only valid identifiers, keywords, comments, "(" and "{" are valid at the start of a code block and they must occur immediately following "@" with no space in between.

      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.Log(ILogger logger, LogLevel logLevel, String message)
      at Microsoft.CodeAnalysis.Razor.Logging.ILoggerExtensions.LogError(ILogger logger, String message)
      at Microsoft.CodeAnalysis.Razor.Formatting.FormattingDiagnosticValidationPass.IsValidAsync(FormattingContext context, ImmutableArray`1 changes, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Razor.Formatting.RazorFormattingService.ApplyFormattedChangesAsync(IDocumentSnapshot documentSnapshot, RazorCodeDocument codeDocument, ImmutableArray`1 generatedDocumentChanges, RazorFormattingOptions options, Int32 hostDocumentIndex, Char triggerCharacter, IFormattingPass formattingPass, Boolean collapseChanges, Boolean automaticallyAddUsings, Boolean validate, String formattingType, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Razor.Formatting.RazorFormattingService.GetCSharpOnTypeFormattingChangesAsync(DocumentContext documentContext, RazorFormattingOptions options, Int32 hostDocumentIndex, Char triggerCharacter, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.Razor.RemoteFormattingService.GetOnTypeFormattingEditsAsync(RemoteDocumentContext context, ImmutableArray`1 htmlChanges, LinePosition linePosition, String triggerCharacter, 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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions