Build/Test Issues

.net 8 Intermittent build issues (System.ArgumentException: An item with the same key has already)

Started by npateman on 1,515 views

Hi there,

My unit test project is intermittently failing to build by NCrunch with the following error,

C:\Program Files\dotnet\sdk\8.0.413\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets: The "GenerateDepsFile" task failed unexpectedly.
System.ArgumentException: An item with the same key has already been added. Key: clypse.core.UnitTests
at System.Collections.Generic.CollectionExtensions.LibraryCollectionToDictionary[T](IReadOnlyList`1 collection)
at Microsoft.Extensions.DependencyModel.DependencyContextWriter.WritePortableTarget(String key, IReadOnlyList`1 runtimeLibraries, IReadOnlyList`1 compilationLibraries, Utf8JsonWriter jsonWriter)
at Microsoft.Extensions.DependencyModel.DependencyContextWriter.WriteTargets(DependencyContext context, Utf8JsonWriter jsonWriter)
at Microsoft.Extensions.DependencyModel.DependencyContextWriter.Write(DependencyContext context, Stream stream)
at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath)
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.NET.Build.Tasks.TaskWithAssemblyResolveHooks.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

I can fix it temporarily by closing visual studio. deleting obj and bin folders, then loading up again. But then a few changes later it's back again.

My version isn't the latest (5.11.0.1). I looked through the forum and found some old mentions about it but nothing new (unless I completely missed it)

Is this something that is addressed with a newer release or is there some kind of workaround?

Btw my solution consists of 2 projects,

clypse.core
clypse.core.UnitTests

Nick.
Hi Nick,

Thanks for sharing this issue. This looks to be a downstream symptom of a project referencing issue, and it feels familiar to me. I remember having fixed something like it in a recent build.

I'd like to confirm whether this is a new issue. I've added a short trial license to your account on this website that you can use to unlock access to the latest version of NCrunch temporarily. Would you mind giving it a try to see if it resolves the issue?

Hi there,

Not entirely sure if it's new tbh, I've not done any personal .net 8 projects for a while. It's not something I've noticed at work that's for sure, so could well be something funky with my project.

It's pretty vanilla, .net 8 class library and xunit test project.

Sure I'll give the new one a try and see how it goes...

Nick.
I just made a whole bunch of changes and the tests continued to work as expected, so looks like it's my dated build.

Thanks for confirming that, I will upgrade to get the latest version.

Nick.

Post a reply

Log in to reply.