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

An exception is thrown when getting the compilation. #66556

Closed
NikiPn opened this issue Jan 26, 2023 · 1 comment
Closed

An exception is thrown when getting the compilation. #66556

NikiPn opened this issue Jan 26, 2023 · 1 comment
Assignees
Labels

Comments

@NikiPn
Copy link

NikiPn commented Jan 26, 2023

Version Used:
4.4.0-3.22518.13

Problem description:
We develop a static analyzer. We faced a problem when getting the compilation of the project. If the GetCompilationAsync method is called for an object of the Microsoft.CodeAnalysis.Project type for any of npgsql projects, an exception is thrown — "An element with the same key but a different value already exists". Key: '(DocumentId, #95f3409a-8ab7-0422-0bf3-4a9d52062636 - LoggerMessage.g.cs)'".

Stack:
at System.Collections.Immutable.ImmutableSortedDictionary'2.FillFromEmpty(IEnumerable'1 items, Boolean overwriteOnCollision) in //src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.cs:line 887
at System.Collections.Immutable.ImmutableSortedDictionary'2.AddRange(IEnumerable'1 items, Boolean overwriteOnCollision, Boolean avoidToSortedMap) in /
/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.cs:line 824
at System.Collections.Immutable.ImmutableSortedDictionary.ToImmutableSortedDictionary[TSource,TKey,TValue](IEnumerable'1 source, Func'2 keySelector, Func'2 elementSelector, IComparer'1 keyComparer) in //src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary.cs:line 173
at Microsoft.CodeAnalysis.TextDocumentStates'1..ctor(IEnumerable'1 states) in /
/src/Workspaces/Core/Portable/Workspace/Solution/TextDocumentStates.cs:line 49
at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.d__40.MoveNext() in //src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.CompilationTracker.cs:line 964
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.d__34.MoveNext() in /
/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.CompilationTracker.cs:line 565
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.d__33.MoveNext() in //src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.CompilationTracker.cs:line 529
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.d__32.MoveNext() in /
/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.CompilationTracker.cs:line 488
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.d__30.MoveNext() in /_/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.CompilationTracker.cs:line 411

Apparently, the problem is related to the auto-generation of files by the Microsoft.Extensions.Logging library (the LoggerMessage attribute).

We should point out that we use bindingRedirect from versions 0.0.0.0 - 4.4.0.0 to 4.4.0.0 for the following packages:

  • Microsoft.CodeAnalysis
  • Microsoft.CodeAnalysis.CSharp
  • Microsoft.CodeAnalysis.CSharp.Features
  • Microsoft.CodeAnalysis.CSharp.Workspaces
  • Microsoft.CodeAnalysis.Features
  • Microsoft.CodeAnalysis.VisualBasic
  • Microsoft.CodeAnalysis.VisualBasic.Features
  • Microsoft.CodeAnalysis.VisualBasic.Workspaces
  • Microsoft.CodeAnalysis.Workspaces
  • Microsoft.CodeAnalysis.Workspaces.MSBuild

And from version 0.0.0.0 - 1.0.0.0 to 1.0.0.0 for the Microsoft.CodeAnalysis.Elfie package.

We would appreciate it if you could help us solve this problem.

Expected Behavior:
Get the compilation.

Actual Behavior:
An exception is thrown.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 26, 2023
@jasonmalinowski jasonmalinowski self-assigned this Oct 10, 2023
@jasonmalinowski jasonmalinowski removed the untriaged Issues and PRs which have not yet been triaged by a lead label Oct 10, 2023
@jasonmalinowski
Copy link
Member

I see this is an older bug that only finally made it my way -- @NikiPn this could indicate the generator is being ran twice; we did merge #64729 which should have fixed this (or at least changed it to a more understandable problem.) If you haven't already moved to newer Roslyn packages, please do so.

I'm going to close this as "fixed" but if you're still seeing issues with latest bits please don't hesitate to reactivate!

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

4 participants