views:

572

answers:

6

I have a 2010 project that is targeting .NET v3.5. Inexplicably I can no longer build v3.5 projects. The project doesn't have ANY references added. It won't even let me add a reference to System.Core as it is added by the 'build system'.

warning CS1685: The predefined type 'System.Func' is defined in multiple assemblies in the global alias; using definition from 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll'

IFilter.cs(82,49): error CS0433: The type 'System.Func' exists in both 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll'

Looks like something is grabbing onto 4.0 but I'm not quite sure how to fix it. Any one else run into this?

Coworker had this same issue. It took a reinstall of Windows to correct the problem

I've opened a bug on this one: https://connect.microsoft.com/VisualStudio/feedback/details/558245/warning-cs1685-when-compiling-a-v3-5-net-application-in-visual-studio-2010

If the compiler is set to verbose I see this:

FrameworkPathOverride = C:\Windows\Microsoft.NET\Framework\v4.0.30319

which is defined as:

Specifies the location of mscorlib.dll and microsoft.visualbasic.dll. This parameter is equivalent to the /sdkpath switch of the vbc.exe compiler.

Some other interesting tidbits: I've created a new project all together and cannot build v3.5 at all. I can build 2.0, 3.0, 3.5 Client Profile, 4.0 and 4.0 Client Profile with no problem. VB.NET can build v3.5 but C# cannot. I've tried a reinstall of .NET 3.5, 4.0 and Visual Studio 2010 with no success. Visual Studio debug logs shown nothing interesting and Safe Mode does not work.

Trying to avoid a Windows reinstall...

EDIT: I've come to realize others are facing this issue as well. Link, Link, Link

A: 

Here a suggestion:

  1. Clean your solution and retry. If no success proceed with step 2.
  2. Unload the project by right-clicking on it and selecting the entry "Unload Project"
  3. Right-click again and select "Edit Project"
  4. Make sure your project targets the correct framework version looking up and setting the value of the following tag:
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  1. Check up the reference list of your project:
<ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
    <Reference Include="Microsoft.CSharp" />
    ...
</ItemGroup>

Make sure there is no double reference.

I hope this helps.

If not, backup your project files, delete the project and re-add the to a new project. This should most likely work.

Simon
Thanks for the hint but the project is targeting 3.5 like it should and has no references at all defined in the project file.
Adam Driscoll
A: 

I guess there might be a reference to the 4.0 framework in a project or solution file - maybe there are different TargetFrameworkVersion elements. Or maybe some of the files in the bin or obj folder are out of sync.

Try cleaning the solution or even manually deleting the content of the bin and obj folder. If this does not help, just compare the current version with the last working version in Subversion or what ever version control system you are using and you should see, were the change happened.

Daniel Brückner
Looks like it's the box and not the project. Notice my edits...
Adam Driscoll
Sounds improbable, but have you looked for assembly redirects in the machine configuration?
Daniel Brückner
How would I go about verifying that? Thanks man
Adam Driscoll
Just locate your Machine.config (%runtime install path%\Config\Machine.config) and look out for the <assemblyBinding> element. While I think about it again, it seems not very logical. Assembly redirecting is a runtime mechanism, I think, and should not affect the compiler. But maybe I am wrong. Further you could also have a look at the assembly loading logs using Fusion Log Viewer from the Windows SDK Tools.
Daniel Brückner
Doesn't seem to be anything of interest. Thanks for the idea though.
Adam Driscoll
A: 

Reinstalled several times. Visual Studio uninstalls do not clean up after themselves. I've spun up a VM to develop on until I have a chance to reinstall my main OS.

Adam Driscoll
A: 

Did anyone get to the bottom of this? I have just encountered the same symptoms. I have both VS2008 and VS2010 installed on my machine. I have been maintaining a VS2008 project using VS2008, targeting .Net 3.5, and all was well for weeks but now when I build the application in VS2008 I get the error about Func being defined in multiple assemblies.

What has changed? Well nothing that should affect that project. I have been developing a WCF 4 web service using VS2010 in parallel. The VS2008 project built fine prior to that and I've only just discovered it will no longer build.

I've now converted my VS2008 project to a VS2010 project, initially exhibiting same issue but when I changed the target for that project to .Net 4 it built fine. Is there a time limit after installing VS2010 after which VS2008 projects will no longer build? Looks like I'm going to have to get my application working with .Net 4 somewhat earlier than I had anticipated.

David Clarke
Yeah I never figured out what the cause was. Did you happen to install the Silverlight 4 SDK?
Adam Driscoll
No, the only thing I was doing was building a VS2010 WCF service targeting .Net 4 and outputting JSON. I had a bit of drama with Resharper and wondered if that had anything to do with it. I use SVN for version control and managed to commit some Resharper files which caused some grief but I use TortoiseSVN for checkins so no VS integration. Did you do anything to work around it?
David Clarke
I spent hours on this and couldn't get it to build anything except 4.0. I started a new question after I realized that it wasn't only when I was building and was actually whenever I selected any framework besides 4.0. http://stackoverflow.com/questions/2813851/target-framework-does-not-change-in-visual-studio-2010My workaround was to spin up a VM and start developing on there. What about the new reflector plugin? I think that may have caused some issues...
Adam Driscoll
No, reflector not installed.
David Clarke
Adam you have just saved me a reinstall, I should have checked back sooner and saved myself some grief. I had applied the same registry changes for PowerShell but after the time elapsed between doing that and attempting to rebuild my app I hadn't made the connection. Thank you.
David Clarke
I had the warnings but not the error and traced the problem to definiton of System.Func in Moq.dll.
Paul Ruane
+4  A: 

The problem was the caused by the changes made in this post. Forcing the loading of the latest CLR version is what caused the problem. Be careful!

Adam Driscoll
A: 

Little cheat: Open VS210 project properties page ob build advanced check do not reference mscorlib.dll. Then in a text editor open the project file and add into the references:

Bye

Alberto Ferrazzoli