Build/Test Issues

Migrating to .NET 5 - An item with the same key has already been added

Started by jpgrassi on 2,275 views

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!

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?
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

Edited

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.
I've taken a deep look through the bug report you submitted. The problem does indeed seem to be triggered by the multi-targeting.

Could you try the build below to see if it resolves the issue?

NCrunch_Console_4.7.0.3.msi
NCrunch_Console_4.7.0.3.zip
NCrunch_GridNodeServer_4.7.0.3.msi
NCrunch_GridNodeServer_4.7.0.3.zip
NCrunch_LicenseServer_4.7.0.3.zip
NCrunch_VS2008_4.7.0.3.msi
NCrunch_VS2010_4.7.0.3.msi
NCrunch_VS2010_4.7.0.3.zip
NCrunch_VS2012_4.7.0.3.msi
NCrunch_VS2012_4.7.0.3.zip
NCrunch_VS2013_4.7.0.3.msi
NCrunch_VS2013_4.7.0.3.zip
NCrunch_VS2015_4.7.0.3.msi
NCrunch_VS2015_4.7.0.3.msi.7z
NCrunch_VS2015_4.7.0.3.zip
NCrunch_VS2017_4.7.0.3.msi
NCrunch_VS2017_4.7.0.3.msi.7z
NCrunch_VS2017_4.7.0.3.zip
NCrunch_VS2019_4.7.0.3.msi
NCrunch_VS2019_4.7.0.3.msi.7z
NCrunch_VS2019_4.7.0.3.zip
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.

Edited

jpgrassi 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.

Post a reply

Log in to reply.