dotnet / dotnet/roslyn

System.ArgumentException: The hintName of the added source file must be unique within a generator. (Parameter 'hintName')

Closed
#84,188 4 comments 1 reaction 1 assignee Claimed by @davidwengier View on GitHub
Area-Razor
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**:
Insiders [11912.234]

**Steps to Reproduce**:

1. Open a Razor file in a razor class library in Visual Studio.
2. Occasionally, Visual studio shows that basically the whole editor has stopped working.
3. Feature 'Razor XXXXX' is unavailable due to an internal error.
4. This issue is intermittent but happens fairly frequently that myself and my team can reproduce it at least once per day.

I filled an issue here:
https://developercommunity.visualstudio.com/t/RazorSourceGenerator-fails-with-CS8785-o/11099219?port=1026&fsid=3c7a53c8-c68d-44c1-bff1-0e29693ba2a6&ref=native&refTime=1781795888797&refUserId=6c055927-8a27-68ef-84b1-b9d12affc8d9

This was duplicated to this issue and then closed:

https://developercommunity.visualstudio.com/t/Multiple-Razor-related-errors-pop-up-in/11094016?port=1026&fsid=3c7a53c8-c68d-44c1-bff1-0e29693ba2a6&ref=native&refTime=1781795888795&refUserId=6c055927-8a27-68ef-84b1-b9d12affc8d9

What logs do you need? @davidwengier

**Expected Behavior**:

The razor syntax highlighting and features using co-hosting work.

**Actual Behavior**:

The visual studio editor instance is broken until either projects are unloaded, reloaded or files opened and closed.

StreamJsonRpc.RemoteInvocationException: Razor source generator did not produce a host output for project 'Opsyte.Portal.UX': warning CS8785: Generator 'RazorSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName 'Pages/Financial/Snapshot/SendSnapshotModal_razor.g.cs' of the added source file must be unique within a generator. (Parameter 'hintName')'.
System.ArgumentException: The hintName 'Pages/Financial/Snapshot/SendSnapshotModal_razor.g.cs' of the added source file must be unique within a generator. (Parameter 'hintName')
at Microsoft.CodeAnalysis.AdditionalSourcesCollection.Add(String hintName, SourceText source)
at Microsoft.CodeAnalysis.AbstractSourceOutputNode`1.AppendOutputs(IncrementalExecutionContext context, CancellationToken cancellationToken)
-----

at StreamJsonRpc.JsonRpc.d__177`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 System.Threading.Tasks.ValueTask`1.get_Result()
at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.d__18`1.MoveNext()
RPC server exception:
System.InvalidOperationException: Razor source generator did not produce a host output for project 'Opsyte.Portal.UX': warning CS8785: Generator 'RazorSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName 'Pages/Financial/Snapshot/SendSnapshotModal_razor.g.cs' of the added source file must be unique within a generator. (Parameter 'hintName')'.
System.ArgumentException: The hintName 'Pages/Financial/Snapshot/SendSnapshotModal_razor.g.cs' of the added source file must be unique within a generator. (Parameter 'hintName')
at Microsoft.CodeAnalysis.AdditionalSourcesCollection.Add(String hintName, SourceText source)
at Microsoft.CodeAnalysis.AbstractSourceOutputNode`1.AppendOutputs(IncrementalExecutionContext context, CancellationToken cancellationToken)
-----

at Microsoft.CodeAnalysis.Remote.Razor.ProjectSystem.GeneratorRunResult.CreateAsync(Boolean throwIfNotFound, Project project, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.Razor.ProjectSystem.RemoteProjectSnapshot.GetRequiredCodeDocumentAsync(IDocumentSnapshot documentSnapshot, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.Razor.ProjectSystem.RemoteDocumentSnapshot.GetGeneratedOutputAsync(CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Razor.ProjectSystem.DocumentContext.g__GetCodeDocumentCoreAsync|10_0(CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.Razor.RemoteLinkedEditingRangeService.GetRangesAsync(RemoteDocumentContext context, LinePosition linePosition, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass7_0`1.<g__ProcessSolutionAsync|1>d.MoveNext()
--- End of stack trace from previous location ---

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.