.net – Could not load file or assembly ‘System.Core, Version=3.5.0.0’

asp.netasp.net-4.0netvisual studiovisual studio 2010

I have an ASP.NET 3.5 solution that was recently upgraded to run on .NET 4.0. Despite that, it seems that most of the projects in the solution are still set to target the .NET 3.5 Framework.

That being said, I can't debug any of these projects now. I get the following error:

Parser Error Message: Could not load file or assembly 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
=== Pre-bind state information ===  
LOG: User = myusername
LOG: DisplayName = System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35  
     (Fully-specified) 
LOG: Appbase = file:///C:/Projects/myprojectpath/ 
LOG: Initial PrivatePath = C:\Projects\myprojectpath\bin 
Calling assembly : (Unknown).
=== 
LOG: This bind starts in default load context. 
LOG: Using application configuration file: C:\Projects\myprojectpath\web.config   
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config. 
LOG: Post-policy reference: System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

I have edited my project file manually, as described here and added the following lines:

<Reference Include="System.Core">
  <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>

But it did no good. Can someone explain why I'm getting this error message and how to resolve it? Thanks!

Best Answer

In my case, there was a line in the web.config that had to be removed.

<pages enableEventValidation="true">
    <namespaces>
        <add namespace="System.Linq"/>
    </namespaces>
    <controls>
        <!--<add tagPrefix="asp" namespace="System.Linq" assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>-->
    </controls>
</pages>

(And actually I was able to safely comment out <add namespace="System.Linq"/> as well.