2010-07-24 60 views
4

當代碼分析運行時,我在構建.NET項目時遇到以下無益的錯誤。它在Visual Studio中發生,並通過命令行與MSBuild建立。代碼分析工具錯誤「給定的鍵在字典中不存在」。

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

什麼是壞的任何想法?


編輯:

有沒有發現,導致它的代碼。我的代碼中有一個方法。

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

如果我添加以下行的第一行代碼的錯誤開始發生的事情,如果我刪除它,錯誤停止。

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

這並沒有什麼意義,因爲我在整個項目中都使用代碼合同。這種方法與其他方法的區別僅在於它有大約200行的XML文字。該方法將輸入文檔轉換爲另一種XML格式,就像XSLT一樣。我的猜測是它與此有關。

+0

也看到VS2017的代碼不顯示在VS2013中。在我們的案例中,我們意外地應用了錯誤的規則集引發了這個問題。 – 2017-09-13 16:55:30

回答

4

這是該工具的內部錯誤。儘管它聽起來像是你找到了一個臨時的解決方法,但你可以做的事情並不多。當您繼續處理源代碼時,它可能會自行解決。儘管這需要一個半滿的玻璃杯。

您可以在connect.microsoft.com上報告錯誤,他們需要一小段代碼來重現錯誤。

0

我有一個類似的問題:

<Exceptions> 
    <Exception Keyword="CA0001" Kind="Engine"> 
    <Type>System.Collections.Generic.KeyNotFoundException</Type> 
    <ExceptionMessage>The given key was not present in the dictionary.</ExceptionMessage> 
    <StackTrace> at System.Collections.Generic.Dictionary`2.get_Item(TKey key) 
    at Microsoft.FxCop.Engines.Phoenix.PreScanPass.AnonymousMethodQueue.ReportDeclaringMethodFound(FunctionSymbol anonymousMethod) 
    at Microsoft.FxCop.Engines.Phoenix.PreScanPass.AnonymousMethodPhase.ExamineInstructionForAnonymousMethodDeclaration(Instruction instruction) 
    at Microsoft.FxCop.Engines.Phoenix.PreScanPass.AnonymousMethodPhase.Execute(Unit unit) 
    at Phx.Phases.PhaseList.DoPhaseList(Unit unit) 
    at Microsoft.FxCop.Engines.Phoenix.PreScanPass.Execute(ModuleUnit moduleUnit) 
    at Phx.Passes.PassList.DoPassList(ModuleUnit moduleUnit) 
    at Microsoft.FxCop.Engines.Phoenix.PhoenixAnalysisEngine.AnalyzeInternal() 
    at Microsoft.FxCop.Engines.Phoenix.PhoenixAnalysisEngine.Analyze() 
    at Microsoft.FxCop.Common.EngineManager.Analyze(Project project, Boolean verboseOutput) </StackTrace> 
</Exception> 

我做了一些調查,發現由於它在VS2012正常工作最有可能的FxCop的錯誤已得到修復,如果只從Visual Studio 2010中運行的FxCop出現這個問題。

在按照方法評論我的更改後,我發現它是由同一類中的2個匿名方法(工作正常,只有一個)引起的。一旦我將它們轉換爲「已命名」方法,錯誤消失。

希望有所幫助。

相關問題