3
votes

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!

2
It should automatically update the references when you change the target framework to .Net 4 from the project properties in VS.M. Mennan Kara
I tried changing the target framework to 4.0, but it didn't help.Jeremy Wiggins
It might be because of the manual editing, normally you need to change the target frameworks of each project individually. What I can suggest is that you create a .net4 project of same type, and try comparing the .csproj file sources to figure out the differences.M. Mennan Kara

2 Answers

1
votes

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.

1
votes

It happened to me that the controls used such as:

<assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

        </assemblies>

Were instead:

 <assemblies>
            <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

        </assemblies>

Or vice versa. You might wanna check that out. Or migrate the whole project (the frames or pages) to a .net 4.0 one. And also sometimes when I need to work on diferent frameworks I remove the target framework line.