I have a Visual Studio solution that was upgraded to use .NET Framework 4.5. It was working fine until I started getting the following error(s) running Code Analysis as part of the build:

CA0052 : No targets were selected

CA0055 : Could not load D:\dev\MySolution\MyProject\bin\Release\MyProject.exe. The following error was encountered while reading module 'System.Xml': Could not resolve type reference: [mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]System.Runtime.CompilerServices.IAsyncStateMachine

That seemed odd, as I confirmed that the application did have an assembly reference to System.Xml. I even tried re-adding the reference but that made no difference. The interesting thing is that the type (IAsyncStateMachine) is new in .NET 4.5, even though it is included in mscorlib Version 4.0.0.0. That’s because 4.5 is an in-place upgrade.

I did notice that you do get separate copies of the reference assemblies located in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework. Reflecting on the mscorlib.dll assembly in the v4.0 folder showed it did NOT have IAsyncStateMachine, but the one in the v4.5 folder did. Could that be relevant?

Opening up the .csproj file, I discovered that another assembly reference suspiciously had the following HintPath defined

<Reference Include="System.Web">

  <HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.dll</HintPath>

</Reference>

Re-adding this reference, resulted in Visual Studio changing it to just this:

<Reference Include="System.Web" />

And then re-building the solution with Code Analysis enabled was successful.