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

[BUG] C# Devkit CommonAssemblyInfo.cs crash #650

Closed
iongion opened this issue Oct 25, 2023 · 11 comments
Closed

[BUG] C# Devkit CommonAssemblyInfo.cs crash #650

iongion opened this issue Oct 25, 2023 · 11 comments
Assignees
Labels
area-project Project load, Solution Explorer bug Something isn't working triaged The issue has been triaged
Milestone

Comments

@iongion
Copy link

iongion commented Oct 25, 2023

Describe the Issue

I have multiple projects in my solution, there is a single project that has a CommonAssemblyInfo.cs that I control through code genereation for CI/CD purposes and code-signing/version aligmented for all the other projects in the solution.

In the other projects I reference the file using this kind of setup

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>true</SelfContained>
    <PublishTrimmed>true</PublishTrimmed>
	<PublishReadyToRun>true</PublishReadyToRun>
	<RuntimeIdentifiers>win-x64;linux-x64;osx-x64;</RuntimeIdentifiers>
  </PropertyGroup>

  <PropertyGroup>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="..\ShotsenseApi\CommonAssemblyInfo.cs" />
  </ItemGroup>

</Project>
=====================
10/25/2023 9:19:52 PM
LimitedFunctionality
System.AggregateException: Project system data flow 'Workspace update handler 34064222' closed because of an exception: 'C:\Workspace\sq\my-api\CommonAssemblyInfo.cs' has already been added to this project. (Parameter 'fullPath'). ('C:\Workspace\sq\my-api\CommonAssemblyInfo.cs' has already been added to this project. (Parameter 'fullPath'))
---> (Inner Exception #0) StreamJsonRpc.RemoteInvocationException: 'C:\Workspace\sq\my-api\CommonAssemblyInfo.cs' has already been added to this project. (Parameter 'fullPath')
   at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult](RequestId id, String targetName, IReadOnlyList`1 arguments, IReadOnlyList`1 positionalArgumentDeclaredTypes, IReadOnlyDictionary`2 namedArgumentDeclaredTypes, CancellationToken cancellationToken, Boolean isParameterObject)
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Handlers.CompileItemHandler.AddToContextAsync(IWorkspaceProject context, ImmutableArray`1 itemsToAdd, Boolean isActiveContext, CallCounts callCounts, IManagedProjectDiagnosticOutputService logger)
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Handlers.AbstractEvaluationCommandLineHandler`1.AddFilesAsync(IWorkspaceProject context, IImmutableSet`1 addedItems, IImmutableDictionary`2 currentMetadata, Boolean isActiveContext, CallCounts callCounts, IManagedProjectDiagnosticOutputService logger, Boolean evaluation)
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Handlers.AbstractEvaluationCommandLineHandler`1.ApplyChangesToContextAsync(IWorkspaceProject context, IProjectChangeDiff difference, IImmutableDictionary`2 previousMetadata, IImmutableDictionary`2 currentMetadata, Boolean isActiveContext, CallCounts callCounts, IManagedProjectDiagnosticOutputService logger, Boolean evaluation)
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Handlers.AbstractEvaluationCommandLineHandler`1.ApplyProjectEvaluationAsync(IWorkspaceProject context, IComparable version, IProjectChangeDiff difference, IImmutableDictionary`2 previousMetadata, IImmutableDictionary`2 currentMetadata, Boolean isActiveContext, ITelemetryOperation telemetryOperation, IManagedProjectDiagnosticOutputService logger)
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Handlers.CompileItemHandler.HandleAsync(IWorkspaceProject context, ProjectConfiguration projectConfiguration, IComparable version, IProjectChangeDescription projectChange, ContextState state, ITelemetryOperation telemetryOperation, IManagedProjectDiagnosticOutputService logger)
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Workspace.<>c__DisplayClass43_1.<<OnEvaluationUpdateAsync>g__ProcessProjectEvaluationHandlersAsync|5>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Workspace.<>c__DisplayClass43_0.<<OnEvaluationUpdateAsync>g__ApplyProjectEvaluationAsync|2>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Workspace.<>c__DisplayClass46_1`1.<<OnProjectChangedAsync>g__ApplyInBatchAsync|1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.VisualStudio.Threading.ReentrantSemaphore.StackSemaphore.<>c__DisplayClass3_0.<<ExecuteAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.VisualStudio.Threading.ReentrantSemaphore.StackSemaphore.ExecuteAsync(Func`1 operation, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.ProjectSystem.OnceInitializedOnceDisposedUnderLockAsync.ExecuteUnderLockCoreAsync(Func`2 action, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Workspace.OnEvaluationUpdateAsync(IProjectVersionedValue`1 evaluationUpdate)
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Workspace.<>c__DisplayClass42_0.<<OnWorkspaceUpdateAsync>g__ApplyUpdateWithinLockAsync|1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Workspace.<>c__DisplayClass42_0.<<OnWorkspaceUpdateAsync>g__ApplyUpdateWithinLockAsync|1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.VisualStudio.ProjectSystem.VSCode.LanguageServices.Workspace.<>c__DisplayClass42_0.<<OnWorkspaceUpdateAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.VisualStudio.Threading.ReentrantSemaphore.StackSemaphore.<>c__DisplayClass3_0.<<ExecuteAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.VisualStudio.Threading.ReentrantSemaphore.StackSemaphore.ExecuteAsync(Func`1 operation, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.ProjectSystem.OnceInitializedOnceDisposedUnderLockAsync.ExecuteUnderLockCoreAsync(Func`2 action, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.ProjectSystem.DataReceivingBlockSlim`1.ProcessInputQueueAsync(InputDataBuffer inputQueue)
<--- (Inner Exception #0) 
===================


Steps To Reproduce

  1. Create a CommonAssemblyInfo.cs in a certain project (disable GenerateAssemblyInfo)
  2. Reference it in another project in the solution using <Compile Include="..\MainProject\CommonAssemblyInfo.cs" />

Expected Behavior

Not to have the error just like Visual Studio (not VSCode) or the dotnet build

Environment Information

It happens on every OS and any VSCode version

@iongion iongion added the bug Something isn't working label Oct 25, 2023
@iongion
Copy link
Author

iongion commented Oct 25, 2023

NOTE: The crash does not affect VSCode in the same way, on Windows VSCode still works properly(in terms of autocomplete and language features, on MacOS none of the features work at all)

@dibarbet dibarbet added the area-project Project load, Solution Explorer label Oct 25, 2023
@dibarbet
Copy link
Member

@tmeschter @jasonmalinowski it looks like we're being called to add a file twice (and throwing). Is this potentially an issue on the project system side where the same file is being added twice?

@tmeschter
Copy link
Member

@dibarbet I would assume this is an issue on the project system side since we try very hard not to send the same file twice. :-) My guess is that the evaluation and design-time builds for CommonAssemblyInfo.cs are giving us different paths (one relative, one full) and we're not able to reconcile them.

@iongion Can you tell me more about CommonAssemblyInfo.cs? Is it a checked-in file, or generated by your build process, or both?

@tmeschter
Copy link
Member

tmeschter commented Oct 26, 2023

Dropping @jasonmalinowski and "area-roslyn" on the assumption that this is strictly a project system issue.

@tmeschter tmeschter added the triaged The issue has been triaged label Oct 26, 2023
@iongion
Copy link
Author

iongion commented Oct 26, 2023 via email

@kvenkatrajan kvenkatrajan added this to the Nov2023 milestone Oct 26, 2023
@jasonmalinowski
Copy link
Member

@tmeschter Yeah, I'd say this is on your side to investigate, at least until you've confirmed it not a simple double add issue.

@iongion
Copy link
Author

iongion commented Oct 26, 2023

Here it is

AwesomeApi.zip

The error log is

Using dotnet configured on PATH
Dotnet path: C:\Program Files\dotnet\dotnet.exe
Activating C# standalone...
waiting for named pipe information from server...
[stdout] {"pipeName":"\\\\.\\pipe\\706c3024-da2c-4753-b6ef-4530dab476a7"}
received named pipe information from server
attempting to connect client to server...
client has connected to server
[Info  - 9:16:05 PM] [Program] Language server initialized
[Info  - 9:16:06 PM] [LanguageServerProjectSystem] Loading c:\Workspace\sq\AwesomeApi\AwesomeApi.sln...
[Error - 9:16:07 PM] [LanguageServerProjectSystem] Exception thrown while loading c:\Workspace\sq\AwesomeApi\AwesomeApi.Common\AwesomeApi.Common.csproj System.ArgumentException: 'c:\Workspace\sq\AwesomeApi\AwesomeApi.Common\AwesomeApi.Common.AssemblyInfo.cs' has already been added to this project. (Parameter 'fullPath')
   at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProject.BatchingDocumentCollection.AddFile(String fullPath, SourceCodeKind sourceCodeKind, ImmutableArray`1 folders) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.BatchingDocumentCollection.cs:line 108
   at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProject.AddSourceFile(String fullPath, SourceCodeKind sourceCodeKind, ImmutableArray`1 folders) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs:line 686
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.<UpdateWithNewProjectInfoAsync>g__UpdateProjectSystemProjectCollection|14_12[T](IEnumerable`1 loadedCollection, IEnumerable`1 oldLoadedCollection, IEqualityComparer`1 comparer, Action`1 addItem, Action`1 removeItem) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 177
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.UpdateWithNewProjectInfoAsync(ProjectFileInfo newProjectInfo) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 106
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.UpdateWithNewProjectInfoAsync(ProjectFileInfo newProjectInfo) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 161
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 245
[Error - 9:16:07 PM] [LanguageServerProjectSystem] Exception thrown while loading c:\Workspace\sq\AwesomeApi\AwesomeApi\AwesomeApi.csproj System.ArgumentException: 'c:\Workspace\sq\AwesomeApi\AwesomeApi\AwesomeApi.AssemblyInfo.cs' has already been added to this project. (Parameter 'fullPath')
   at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProject.BatchingDocumentCollection.AddFile(String fullPath, SourceCodeKind sourceCodeKind, ImmutableArray`1 folders) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.BatchingDocumentCollection.cs:line 108
   at Microsoft.CodeAnalysis.Workspaces.ProjectSystem.ProjectSystemProject.AddSourceFile(String fullPath, SourceCodeKind sourceCodeKind, ImmutableArray`1 folders) in /_/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs:line 686
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.<UpdateWithNewProjectInfoAsync>g__UpdateProjectSystemProjectCollection|14_12[T](IEnumerable`1 loadedCollection, IEnumerable`1 oldLoadedCollection, IEqualityComparer`1 comparer, Action`1 addItem, Action`1 removeItem) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 177
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.UpdateWithNewProjectInfoAsync(ProjectFileInfo newProjectInfo) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 106
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.UpdateWithNewProjectInfoAsync(ProjectFileInfo newProjectInfo) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 161
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 245
[Info  - 9:16:07 PM] [LanguageServerProjectSystem] Completed (re)load of all projects in 00:00:01.2744895
[Error - 9:16:09 PM] [LanguageServerProjectSystem] Exception thrown while loading c:\Workspace\sq\AwesomeApi\AwesomeApi\AwesomeApi.csproj System.InvalidOperationException: We haven't been given a loaded project yet, so we can't provide the existing TFM. - line 68
   at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/Contract.cs:line 154
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.GetTargetFramework() in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 68
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.<>c__DisplayClass16_1.<LoadOrReloadProjectAsync>b__2(LoadedProject p) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 224
   at System.Collections.Generic.List`1.Find(Predicate`1 match)
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 224
[Error - 9:16:09 PM] [LanguageServerProjectSystem] Exception thrown while loading c:\Workspace\sq\AwesomeApi\AwesomeApi.Common\AwesomeApi.Common.csproj System.InvalidOperationException: We haven't been given a loaded project yet, so we can't provide the existing TFM. - line 68
   at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber) in /_/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/Contract.cs:line 154
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LoadedProject.GetTargetFramework() in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LoadedProject.cs:line 68
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.<>c__DisplayClass16_1.<LoadOrReloadProjectAsync>b__2(LoadedProject p) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 224
   at System.Collections.Generic.List`1.Find(Predicate`1 match)
   at Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.LanguageServerProjectSystem.LoadOrReloadProjectAsync(ProjectToLoad projectToLoad, BuildHostProcessManager buildHostProcessManager, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs:line 224
[Info  - 9:16:09 PM] [LanguageServerProjectSystem] Completed (re)load of all projects in 00:00:01.1220789

Screenshot from VSCode

image

@iongion
Copy link
Author

iongion commented Oct 26, 2023

Also this if of any help

image

@tmeschter
Copy link
Member

The AswesomeApi.zip projects contain items like this:

<ItemGroup>
  <Compile Include=".\AwesomeApi.AssemblyInfo.cs" />
</ItemGroup>

Note the leading ".\" which indicates "in the current directory" much like "..\" would indicate "in the parent directory".

There are a couple of interesting things here:

  1. The leading "." isn't necessary as relative paths are assumed to be relative to the project directory. <Compile Include="AwesomeApi.AssemblyInfo.cs" /> would mean the same thing.
  2. The whole <Compile ... /> item is unnecessary as the default globs will include all .cs files under the project directory.

What ends up happening is that at the MSBuild level we have two items with distinct Includes that happen to point to the same file:

  • .\AwesomeApi.AssemblyInfo.cs
  • AwesomeApi.AssemblyInfo.cs

The Project System converts both items to their full paths, which end up being the same:

  • C:\bar\AwesomeApi.AssemblyInfo.cs
  • C:\bar\AwesomeApi.AssemblyInfo.cs

It makes the erroneous assumption that because the input items were unique (in that they had different Includes) the full paths will also be unique. It then passes both full paths to the Language Service, which catches the duplication and throws an exception.

(If the Language Service hadn't thrown the Project System would have caught the almost immediately after when updating its own internal state, where we have a sanity check for duplicates.)

The fix here will be to eliminate the assumption that unique Includes lead to unique full paths, and filter out duplicates before we pass them to the Language Service.

@tmeschter
Copy link
Member

This was actually fixed for December 2023.

@huci-youfan
Copy link

This was actually fixed for December 2023.

It seems like this issue hasn't been fixed, and I encountered it in my latest version of VS Code. I searched through all the files in the solution, and it didn't appear that DB_ProductSkcExtend.cs was referenced twice; however, there is an issue where the solution indeed contains two such files, including a case-insensitive match DB_ProductSKCExtend.cs.

Strangely, VS treats them as the same file, and double-clicking on either one opens the DB_ProductSKCExtend.cs file, which contains the class DB_ProductSkcExtend.

<Compile Include="DB_ProductSKCExtend.cs" />
<Compile Include="DB_ProductSkcExtend.cs" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-project Project load, Solution Explorer bug Something isn't working triaged The issue has been triaged
Projects
None yet
Development

No branches or pull requests

7 participants