views:

29

answers:

1

I get the following unhelpful error while building my .NET project when Code Analysis runs. It happens both in Visual Studio and building from the command line with MSBuild.

  * 1 total analysis engine exceptions.
MSBUILD : error : CA0001 : The given key was not present in the dictionary.

Any ideas on what is broken?


Edit:

Have found the code that causes it. I have a method in my code.

Public Function Generate(ByVal input As XDocument) As XDocument
   ' My code
End Function

If I add the following line as the first line of code the error starts happening, if I remove it, the error stops.

Contract.Requires(Of ArgumentNullException)(partCover IsNot Nothing, "input")

It doesn't really make sense as I'm using Code Contracts all through out my project. The only thing different about this method from any other is that it has about 200 lines of XML literals in it. The method transforms the input document to another XML format much like an XSLT. My guess is that it has something to do with that.

+2  A: 

This is an internal error in the tool. There's isn't much you can do about it, although it sounds like you found a temporary workaround. It is possible that it resolves itself when you keep working on the source code. Albeit that would require a glass that's half full.

You can report the bug at connect.microsoft.com, they'll need a small sample of your code that can reproduce the bug for them.

Hans Passant