7

I am trying to run Code Analysis for the first time against a number of different solutions we have. Each time I get a CA0055 error ("Could not load target") despite the fact that the target file very much does exists.

I've looked at the CodeAnalysis log and I can't work out what it's not able to do.

I'm running Visual Studio 2015 (Update 3) on Windows 10, but I've had this problem on VS2013 too. The project is an ASP.NET Web Forms app targeting .NET 4.6.2 but developed from ASP.NET WebForms 2.0. I've got the same issue on a console app too.

The Exception stack trace looks like the following - I know it's probably not much to go on, but it looks like some kind of issue loading a reference maybe?

I'd appreciate any advice - thanks.

<Exception Keyword="CA0055" Kind="AssemblyLoad">
   <Type>Microsoft.FxCop.Common.AssemblyLoadException</Type>
   <ExceptionMessage>Could not load c:\PathToFile\FileBeingAnalysed.dll.</ExceptionMessage>
   <InnerType>System.NullReferenceException</InnerType>
   <InnerExceptionMessage>Object reference not set to an instance of an object.</InnerExceptionMessage>
   <InnerStackTrace>   at Microsoft.FxCop.Sdk.TypeNode.GetNestedType(Identifier name)
   at Microsoft.FxCop.Sdk.Duplicator.VisitTypeReference(TypeNode type)
   at Microsoft.FxCop.Sdk.Duplicator.VisitTypeNode(TypeNode type, Identifier mangledName, TypeNodeCollection templateArguments, TypeNode template, Boolean delayVisitToNestedTypes)
   at Microsoft.FxCop.Sdk.TypeNode.GetTemplateInstance(ModuleNode module, TypeNode referringType, TypeNode declaringType, TypeNodeCollection templateArguments)
   at Microsoft.FxCop.Sdk.TypeNode.GetGenericTemplateInstance(ModuleNode module, TypeNodeCollection consolidatedArguments)
   at Microsoft.FxCop.Sdk.Reader.ParseTypeSignature(MemoryCursor sigReader, Boolean&amp; pinned, Boolean&amp; isTypeArgument)
   at Microsoft.FxCop.Sdk.Reader.GetTypeFromSpec(Int32 i)
   at Microsoft.FxCop.Sdk.Reader.DecodeAndGetTypeDefOrRefOrSpec(Int32 codedIndex)
   at Microsoft.FxCop.Sdk.Reader.GetTypeFromDefHelper(Int32 i)
   at Microsoft.FxCop.Sdk.Reader.GetTypeFromDef(Int32 i)
   at Microsoft.FxCop.Sdk.Reader.GetNestedTypes(TypeNode type, Object handle)
   at Microsoft.FxCop.Sdk.TypeNode.get_NestedTypes()
   at Microsoft.FxCop.Sdk.TypeNode.GetNestedType(Identifier name)
   at Microsoft.FxCop.Sdk.Duplicator.VisitTypeReference(TypeNode type)
   at Microsoft.FxCop.Sdk.Duplicator.VisitTypeNode(TypeNode type, Identifier mangledName, TypeNodeCollection templateArguments, TypeNode template, Boolean delayVisitToNestedTypes)
   at Microsoft.FxCop.Sdk.TypeNode.GetTemplateInstance(ModuleNode module, TypeNode referringType, TypeNode declaringType, TypeNodeCollection templateArguments)
   at Microsoft.FxCop.Sdk.TypeNode.GetGenericTemplateInstance(ModuleNode module, TypeNodeCollection consolidatedArguments)
   at Microsoft.FxCop.Sdk.Reader.ParseTypeSignature(MemoryCursor sigReader, Boolean&amp; pinned, Boolean&amp; isTypeArgument)
   at Microsoft.FxCop.Sdk.Reader.GetTypeFromSpec(Int32 i)
   at Microsoft.FxCop.Sdk.Reader.DecodeAndGetTypeDefOrRefOrSpec(Int32 codedIndex)
   at Microsoft.FxCop.Sdk.Reader.GetTypeFromDefHelper(Int32 i)
   at Microsoft.FxCop.Sdk.Reader.GetTypeFromDef(Int32 i)
   at Microsoft.FxCop.Sdk.Reader.GetNestedTypes(TypeNode type, Object handle)
   at Microsoft.FxCop.Sdk.TypeNode.get_NestedTypes()
   at Microsoft.FxCop.Sdk.TypeNode.GetNestedType(Identifier name)
   at Microsoft.FxCop.Sdk.Duplicator.VisitTypeReference(TypeNode type)
   at Microsoft.FxCop.Sdk.Duplicator.VisitTypeNode(TypeNode type, Identifier mangledName, TypeNodeCollection templateArguments, TypeNode template, Boolean delayVisitToNestedTypes)
   at Microsoft.FxCop.Sdk.TypeNode.GetTemplateInstance(ModuleNode module, TypeNode referringType, TypeNode declaringType, TypeNodeCollection templateArguments)
   at Microsoft.FxCop.Sdk.TypeNode.GetGenericTemplateInstance(ModuleNode module, TypeNodeCollection consolidatedArguments)
   at Microsoft.FxCop.Sdk.Reader.ParseTypeSignature(MemoryCursor sigReader, Boolean&amp; pinned, Boolean&amp; isTypeArgument)
   at Microsoft.FxCop.Sdk.Reader.GetTypeFromSpec(Int32 i)
   at Microsoft.FxCop.Sdk.Reader.DecodeAndGetTypeDefOrRefOrSpec(Int32 codedIndex)
   at Microsoft.FxCop.Sdk.Reader.GetTypeFromDefHelper(Int32 i)
   at Microsoft.FxCop.Sdk.Reader.GetTypeFromDef(Int32 i)
   at Microsoft.FxCop.Sdk.Reader.GetTypeIfNotGenericInstance(Int32 codedIndex)
   at Microsoft.FxCop.Sdk.Reader.ConstructCorrectTypeNodeSubclass(Int32 i, Identifier namesp, Int32 firstInterfaceIndex, Int32 lastInterfaceIndex, TypeFlags flags, InterfaceCollection interfaces, Int32 baseTypeCodedIndex, Boolean isSystemEnum)
   at Microsoft.FxCop.Sdk.Reader.GetTypeFromDefHelper(Int32 i)
   at Microsoft.FxCop.Sdk.Reader.GetTypeFromDef(Int32 i)
   at Microsoft.FxCop.Sdk.Reader.GetTypeList(ModuleNode module)
   at Microsoft.FxCop.Sdk.ModuleNode.get_Types()
   at Microsoft.FxCop.Common.AssemblyNodeEx.GetAllModuleReferences(AssemblyNode assembly)
   at Microsoft.FxCop.Common.CommonUtilitiesProvider.GetAssemblyThread()
   at Microsoft.FxCop.Common.CommonUtilitiesProvider.GetAssembly(String fileName, Boolean hookUpResolver, Boolean getDebugInfo, Boolean useGlobalCache)
   at Microsoft.FxCop.Common.CommonUtilitiesProvider.GetAssembly(String fileName, Boolean hookUpResolver)
   at Microsoft.FxCop.Engines.Introspection.IntrospectionAnalysisEngine.CanLoadTargetFile(TargetFile target)
   at Microsoft.FxCop.Common.EngineManager.LoadTargets(TargetFile target, Boolean resetCounts, String loadEngine)</InnerStackTrace>
  </Exception>
alergy
  • 974
  • 1
  • 14
  • 28
  • 1
    I've reported this issue at [Connect](https://connect.microsoft.com/VisualStudio/feedback/details/3141321/fxcop-fails-with-nullreferenceexception-while-loading-certain-assemblies-ca0055) as our customers are also affected. The core issue in FxCop (as far as I could debug it) is that it will create some sort of type hierarchy from all loaded assemblies, presumably to obtain symbol information during analysis, and cannot find a certain nested type in its data structure. For unknown reasons. – Joey Sep 21 '17 at 10:01
  • Thanks for the update and the link to Connect - ugh to NullReferenceExceptions! – alergy Sep 21 '17 at 13:26
  • https://social.msdn.microsoft.com/Forums/sqlserver/en-US/5800c4eb-f613-4196-9a49-36c097776fa2/error-additional-code-analysis-warnings-or-errors-cannot-be-displayed?forum=vstscode - that is probably something to go on, it has been an issue before... Here is some one else experiencing the same issue https://stackoverflow.com/questions/29298558/visual-studio-2013-code-analysis-exception-ca0055-could-not-load-assembly – Trevor Sep 27 '17 at 19:36
  • @Codexer: That issue on the MSDN fora is a completely different exception with a drastically different stack trace. I'd guess that's an unrelated issue. – Joey Sep 28 '17 at 09:34

0 Answers0