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

Notification

Icon
Error

An item with the same key has already been added
jschreuder
#1 Posted : Monday, October 5, 2015 11:06:07 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/5/2015(UTC)
Posts: 42
Location: Australia

Thanks: 14 times
Was thanked: 23 time(s) in 11 post(s)
Hi Remco.

I've seen this issue posted before (example) but it is happening for me now with v2.16.0.13 in VS2013.

One of my projects fails to build with:
Code:

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 _Mono.Cecil.MetadataReader.InitializeRanges(Table table, Func`1 get_next)
   at _Mono.Cecil.MetadataReader.InitializeCustomAttributes()
   at _Mono.Cecil.MetadataReader.ReadCustomAttributes(ICustomAttributeProvider owner)
   at _Mono.Cecil.Mixin.<GetCustomAttributes>b__8(ICustomAttributeProvider provider, MetadataReader reader)
   at _Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
   at _Mono.Cecil.Mixin.GetCustomAttributes(ICustomAttributeProvider self, ModuleDefinition module)
   at _Mono.Cecil.AssemblyDefinition.get_CustomAttributes()
   at nCrunch.Compiler.StaticManipulation.BuiltAssembly.()
   at nCrunch.Compiler.StaticManipulation.BuiltAssembly..ctor(FilePath builtAssemblyFilePath, IList`1 adjustedAssemblyReferences, IDictionary`2 codeFilePathsByWorkspaceFilePath, Boolean instrumentForPerformanceMeasurement, Boolean detectStackOverflow)
   at nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters , FilePath , BuildOutput , DirectoryPath[] , FilePath[] )
   at nCrunch.Compiler.RemoteBuildRunner.Build(ComponentBuildParameters parameters)


The weird thing is if I edit this project, it seems to be related to a set of partial classes:
Code:

<Compile Include="Module.cs" />
<Compile Include="Module.A.cs">
  <DependentUpon>Module.cs</DependentUpon>
</Compile>
<Compile Include="Module.B.cs">
  <DependentUpon>Module.cs</DependentUpon>
</Compile>


When I comment out either Module.A.cs part or Module.B.cs part, and disable the related code my project builds correctly.
It doesn't appear to be because of the DependentUpon, as if I remove these lines, it still won't build.

Unfortunately my attempts to reproduce this with a new solution with similar structure failed for some reason, so I can't send you a sample solution.

I've submitted a set of logs (one where I've commented out a module and one where it is broken) for you to take a look at via the Contact form.

I hope you can provide a fix because NCrunch is awesome :)
Remco
#2 Posted : Tuesday, October 6, 2015 12:38:57 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)
Hi, thanks for sharing this issue.

Looking at the stack trace, this problem appears to be caused by some kind of metadata corruption or new IL arrangement that NCrunch/cecil is unfamiliar with. Unfortunately the only way for me to troubleshoot this problem is to have a code sample that can reliably reproduce it.

I'm not entirely convinced that the problem is being caused by the syntax you've described in the project file. Most likely it's related to code contained within these files that is causing the corruption or IL arrangement to surface. Check whether the files contain any interesting/complex snippets of code.. such as attributes containing nullable parameters or very rarely used features of the CLR.

If you are using any post-build assembly manipulation tools (such as PostSharp or Frody), try disabling these to see if there is any difference.
jschreuder
#3 Posted : Wednesday, October 7, 2015 1:13:20 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/5/2015(UTC)
Posts: 42
Location: Australia

Thanks: 14 times
Was thanked: 23 time(s) in 11 post(s)
Remco;7810 wrote:
Most likely it's related to code contained within these files that is causing the corruption or IL arrangement to surface. Check whether the files contain any interesting/complex snippets of code.. such as attributes containing nullable parameters or very rarely used features of the CLR.


I don't think I'm using any weird stuff.

Remco;7810 wrote:
If you are using any post-build assembly manipulation tools (such as PostSharp or Frody), try disabling these to see if there is any difference.


I'm not using any of these types of tools.
Remco
#4 Posted : Wednesday, October 7, 2015 1:25:30 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)
Some more interesting clues that I hope will help with isolating the issue:

- The issue seems to be caused by an assembly-level attribute
- The issue is caused by having more than one range within the assembly with the same metadata token. This is a little beyond my current understanding of the CLR specification, but it does look to be a very wrong thing.

I realise sharing any of your source code with me isn't an option. What about compiled assemblies?
Remco
#5 Posted : Wednesday, October 7, 2015 10:09:50 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)
1 user thanked Remco for this useful post.
jschreuder on 10/8/2015(UTC)
jschreuder
#6 Posted : Wednesday, October 7, 2015 9:58:19 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/5/2015(UTC)
Posts: 42
Location: Australia

Thanks: 14 times
Was thanked: 23 time(s) in 11 post(s)
Remco;7819 wrote:
Thanks for sharing the binaries with me. I've managed to reproduce and fix the issue. You're welcome to give the fix a try if you like:


Thanks for sticking with me to help resolve this :)

I've installed the new build and am getting a new error on the same project now:

Quote:

System.NullReferenceException: Object reference not set to an instance of an object.
at nCrunch.Compiler.StaticManipulation.BuiltAssembly.(CustomAttribute )
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at nCrunch.Compiler.StaticManipulation.BuiltAssembly.()
at nCrunch.Compiler.StaticManipulation.BuiltAssembly..ctor(FilePath builtAssemblyFilePath, IList`1 adjustedAssemblyReferences, IDictionary`2 codeFilePathsByWorkspaceFilePath, Boolean instrumentForPerformanceMeasurement, Boolean detectStackOverflow)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters , FilePath , BuildOutput , DirectoryPath[] , FilePath[] )
at nCrunch.Compiler.RemoteBuildRunner.Build(ComponentBuildParameters parameters)


I've submitted a new bug report via the Submit Bug Report menu item. Hope it helps!
Remco
#7 Posted : Thursday, October 8, 2015 4:09:10 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)
1 user thanked Remco for this useful post.
jschreuder on 10/8/2015(UTC)
jschreuder
#8 Posted : Thursday, October 8, 2015 5:47:05 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 10/5/2015(UTC)
Posts: 42
Location: Australia

Thanks: 14 times
Was thanked: 23 time(s) in 11 post(s)
Thanks - unfortunately still not a go, back to a similar error to the first one, but no longer around ranges but nested types:

Code:

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 _Mono.Cecil.MetadataReader.InitializeNestedTypes()
at _Mono.Cecil.MetadataReader.InitializeTypeDefinitions()
at _Mono.Cecil.MetadataReader.ReadTypes()
at _Mono.Cecil.ModuleDefinition.<get_Types>b__8(ModuleDefinition _, MetadataReader reader)
at _Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
at _Mono.Cecil.ModuleDefinition.get_Types()
at  .()
at nCrunch.Compiler.StaticManipulation.BuiltAssembly.Instrument(ComponentSourceLineMap sourceLineMap, IDictionary`2 instrumentationDirectivesByCodeFileId, IDictionary`2 codeFileIDsByFilePath, Boolean proxyProcessIsActive, Int32 componentId, IInstrumentationFilter[] instrumentationFilters)
at nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters , FilePath , BuildOutput , DirectoryPath[] , FilePath[] )
at nCrunch.Compiler.RemoteBuildRunner.Build(ComponentBuildParameters parameters)


I've sent in a new bug report. Thanks for being so patient with trying to figure this out.
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.061 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download