Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename crashes with source generated partial method signatures #77986

Open
vsfeedback opened this issue Apr 3, 2025 · 0 comments
Open

Rename crashes with source generated partial method signatures #77986

vsfeedback opened this issue Apr 3, 2025 · 0 comments
Assignees
Labels

Comments

@vsfeedback
Copy link

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


[severity:It bothers me. A fix would be nice]
I have a logging class that uses source generators to help with logging Api calls: internal static partial class ApiLogger. This class has a number of methods that are defined for example like this:

    [LoggerMessage(
        Message = "Api {httpMethod} {methodName}. User: {principal}. Parameters: {parametersJson}.",
        Level = LogLevel.Information
        )]
    internal static partial void LogApiCallWithParameters(this ILogger logger,
        HttpMethod httpMethod,
        string methodName,
        PrincipalLogFormatter principal,
        string parametersJson
        );

If using rename command on one of the parameters, VS will give an error "Feature 'Rename' is currently unavailable due to an internal error." and a stack trace:

StreamJsonRpc.RemoteInvocationException: The given key 'SourceFile(C:\my-project\obj\Debug\net8.0\Microsoft.Gen.Logging\Microsoft.Gen.Logging.LoggingGenerator\Logging.g.cs[5972..5983))' was not present in the dictionary.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__156`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.<TryInvokeAsync>d__18`1.MoveNext()
RPC server exception:
System.Collections.Generic.KeyNotFoundException: The given key 'SourceFile(C:\my-project\obj\Debug\net8.0\Microsoft.Gen.Logging\Microsoft.Gen.Logging.LoggingGenerator\Logging.g.cs[5972..5983))' was not present in the dictionary.
      at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
      at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
      at System.Collections.Immutable.ImmutableArray`1.Builder.AddRange(IEnumerable`1 items)
      at Microsoft.CodeAnalysis.CSharp.Rename.CSharpRenameConflictLanguageService.ComputeDeclarationConflictsAsync(String replacementText, ISymbol renamedSymbol, ISymbol renameSymbol, IEnumerable`1 referencedSymbols, Solution baseSolution, Solution newSolution, IDictionary`2 reverseMappedLocations, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Rename.ConflictEngine.ConflictResolver.AddDeclarationConflictsAsync(ISymbol renamedSymbol, ISymbol renameSymbol, IEnumerable`1 referencedSymbols, MutableConflictResolution conflictResolution, IDictionary`2 reverseMappedLocations, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Rename.ConflictEngine.ConflictResolver.Session.IdentifyConflictsAsync(HashSet`1 documentIdsForConflictResolution, IEnumerable`1 allDocumentIdsInProject, ProjectId projectId, MutableConflictResolution conflictResolution, ImmutableHashSet`1 conflictLocations)
      at Microsoft.CodeAnalysis.Rename.ConflictEngine.ConflictResolver.Session.ResolveConflictsAsync()
      at Microsoft.CodeAnalysis.Rename.ConflictEngine.ConflictResolver.ResolveSymbolicLocationConflictsInCurrentProcessAsync(SymbolicRenameLocations renameLocations, String replacementText, ImmutableArray`1 nonConflictSymbolKeys, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteRenamerService.<>c__DisplayClass4_0.<<ResolveConflictsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      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.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)

I'd guess it's a common problem when using automated features with source generation.


Original Comments

Feedback Bot on 31/3/2025, 01:48 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 3, 2025
@deepakrathore33 deepakrathore33 removed the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants