Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Migrating to .NET 5 - An item with the same key has already been added
jpgrassi
#1 Posted : Monday, January 25, 2021 4:50:02 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/25/2021(UTC)
Posts: 4
Location: Argentina

Thanks: 2 times
Hello,

I have an ASP.NET Core project which is targeting netcoreapp3.1. I started upgrading it to net5.0 both the projects themselves and the test project and I started having this error:

An error occurred while analysing this project after it was built: NCrunch encountered an unexpected error occurred while building an environment to analyse an assembly: System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at nCrunch.Core.InlineModules.AspNetMvcTestHostModule.AspNetMvcTestHostExtension.(SnapshotComponent , IList`1 , ProcessLoadParameters )
at nCrunch.Core.TestManagement.TestRunnerProcess.(Nullable`1 , FilePath , GridClientId , CustomVariable[] )
at nCrunch.Core.TestManagement.TestRunnerProcess..()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.Core.TestManagement.TestRunnerProcess.LoadTestRunnerProcessForProjectReturningProcessId(SnapshotComponent snapshotComponent, IList`1 componentsInProcess, TestFrameworkDescription[] testingFrameworks, Nullable`1 newProcessTag, FilePath solutionFilePath, GridClientId client, CustomVariable[] customEnvironmentVariables)
at nCrunch.Core.Processing.AnalysisTaskLogic.DoProcessTaskAndReturnSuccessFlag()

I tried cleaning the NCrunch cache, cleaning and rebuilding the solution, nothing seems to help.

I have some other ASP.NET Core project which is migrated to net5.0 and it works normally. NCrunch runs the tests just fine.

Let me know what can I do to help debugging. I tried looking at the logs (via reporting a bug then looking at the .zip file) but couldn't find anything.

Thanks!

Remco
#2 Posted : Monday, January 25, 2021 11:28:28 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for sharing this problem.

It looks like you have two projects in your solution with the same compiled assembly name (or very similar, with '_' and '.' being interchangeable). This causes clashing inside NCrunch's handling for the AspNetMvcTestHost system. I would expect such a setup to potentially also cause other problems with assembly resolution. Is it intentional?
jpgrassi
#3 Posted : Tuesday, January 26, 2021 8:19:36 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/25/2021(UTC)
Posts: 4
Location: Argentina

Thanks: 2 times
Hi!

We have the project and test project with the same name, only at the end we have ".Tests". So for ex: My.Project -> My.Project.Tests.

It has always worked without any issues. The problem only surfaces when I change the TargetFramework to net5.0. If I return to netcoreapp3.0 it works without problems.

Edit: I tried even renaming the test project to something different, and it still fails. In the UI I see this: https://i.imgur.com/De0vGb8.png
jpgrassi
#4 Posted : Tuesday, January 26, 2021 9:28:02 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/25/2021(UTC)
Posts: 4
Location: Argentina

Thanks: 2 times
More investigations: There's one class library that multi-targets <TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks> and it's intentional since we don't have all projects yet to net5.0. If I make it target only netcoreapp3.1 then NCrunch is happy again.

But the part that I don't understand is: In the solution there's just 1 project + test on net5.0 and this net5.0 project references the multi-targeting class library above. All works. But as soon as I migrate another project, doesn't matter which (We have several APIs in the same solution) then NCrunch complains.
Remco
#5 Posted : Wednesday, January 27, 2021 4:51:03 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
2 users thanked Remco for this useful post.
jpgrassi on 1/27/2021(UTC), upper on 1/28/2021(UTC)
jpgrassi
#6 Posted : Wednesday, January 27, 2021 9:22:13 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/25/2021(UTC)
Posts: 4
Location: Argentina

Thanks: 2 times
Hello,

Thanks for looking into it, really appreciate it.

I tried with the build you posted and I can confirm that it works now.

Edit: Sorry for the nagging, but you have an idea if this fix is making to the next release? And if so, do you have maybe an estimate? Or if this build you sent is considered "prod ready" we would also be fine using it while the official release comes.
Remco
#7 Posted : Wednesday, January 27, 2021 1:22:10 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,144

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
jpgrassi;15281 wrote:

Edit: Sorry for the nagging, but you have an idea if this fix is making to the next release? And if so, do you have maybe an estimate? Or if this build you sent is considered "prod ready" we would also be fine using it while the official release comes.


Yes, it will be in the next release, which we hope to have out in a couple of weeks. However, the build enough should be stable enough to use in production, so there's no need to wait for it to be published on the download page.
1 user thanked Remco for this useful post.
jpgrassi on 1/27/2021(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.067 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download