Skip to content

Source generators in multi-targeted project being loaded twice #65996

@Sergio0694

Description

@Sergio0694

Version Used: 17.4.3, 17.5.0 Preview 3.0 [33213.424.main]

Steps to Reproduce:

  1. Reference the MVVM Toolkit 8.1.0-preview2
  2. ...? Try using it in a project that also references a library using the MVVM Toolkit? It's not entirely clear to me what the exact repro steps are, but I'm seeing a bunch of reports of similar issues from users of the MVVM Toolkit in several scenarios (eg. Compilation Error on .NET Framework CommunityToolkit/dotnet#495)

Note: by multi-targeting I mean the MVVM Toolkit generators that are multi-targeting Roslyn 4.0 and 4.3

This completely broke the Microsoft Store solution as well, so I could use some help 😅

I can also help folks checkout in the repo if needed, otherwise there might be a small public one in the linked issue.

cc. @sharwell @chsienki help? 🥲

I'm clearly seeing analyzers being loaded twice:

image

I'm also seeing a bunch of random errors from other analyzers crashing (not from the MVVM Toolkit).
Not entirely sure whether it's related. For instance:

StreamJsonRpc.RemoteInvocationException: An element with the same key but a different value already exists. Key: '(DocumentId, #28831a34-a993-7077-19bf-b4a7d74f060e - __IMessengerExtensions.g.cs)'
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__143`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__17.MoveNext()
RPC server exception:
System.ArgumentException: An element with the same key but a different value already exists. Key: '(DocumentId, #28831a34-a993-7077-19bf-b4a7d74f060e - __IMessengerExtensions.g.cs)'
      at System.Collections.Immutable.ImmutableSortedDictionary`2.FillFromEmpty(IEnumerable`1 items, Boolean overwriteOnCollision)
      at System.Collections.Immutable.ImmutableSortedDictionary`2.AddRange(IEnumerable`1 items, Boolean overwriteOnCollision, Boolean avoidToSortedMap)
      at System.Collections.Immutable.ImmutableSortedDictionary.ToImmutableSortedDictionary[TSource,TKey,TValue](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IComparer`1 keyComparer)
      at Microsoft.CodeAnalysis.TextDocumentStates`1..ctor(IEnumerable`1 states)
      at Microsoft.CodeAnalysis.SolutionState.CompilationTracker.<FinalizeCompilationAsync>d__40.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-ExternalArea-IDEResolution-ExternalThe behavior lies outside the functionality covered by this repositoryuntriagedIssues and PRs which have not yet been triaged by a lead

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions