Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous invocation caused by picking up two versions of System.Linq

I have the following code, which shows a squiggly red line under the lambda expression after .Any( because of an "ambiguous invocation" between System.Linq versions 3.5 and 4.0 - how do I force it to use a particular version?

It compiles and runs fine.

string[] allowedExtensions = { "PNG", "JPG", "JPEG", "GIF" };
string fileExtension = (Path.GetExtension(postedFile.FileName) ?? "NULL").ToUpper().TrimStart(new[] { '.' });

if (this.MediaService.FileAllowed(postedFile) 
    && allowedExtensions.Any(e => e == fileExtension))
{ ... }

UPDATE:

I've now checked all (60) projects in the entire solution and all the references to System.dll and System.Core.dll are version 4.0 - I really can't understand where it's getting the reference to 3.5 from.

like image 267
greg84 Avatar asked Feb 15 '12 17:02

greg84


1 Answers

I had this problem after ReSharper offered to 'reference System.Core' and 'import System.Linq' in a file where I was using a Linq expression but hadn't yet imported 'System.Linq'. When I executed the ReSharper command, I got some error that part of it had failed. Then all Linq expressions in my project were ambiguous between System.Core 3.5 and 4.0. Looking at all my System and System.Core references, they were 4.0. Removing the reference to System.Core (4.0) caused the ambiguity errors to go away, and made System.Core disappear from the list of references for that project. When I went back to re-add System.Core, although it did not appear in my list of references in Solution Explorer, it was checked in the 'Add Reference to ' dialog. Attempting to un-check it there and then re-check it resulted in an error that System.Core is already referenced by my project. I'm still fixing errors so I don't know if this will affect the build process.

like image 159
Carl G Avatar answered Sep 23 '22 01:09

Carl G