4

This is a long shoot but I have run out of own ideas.

Recently my TeamCity builds have started to throw this error upon me:

File.cs(Row, Col): error CS0411: The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

But there are no errors in my code (or project configuration).

It compiles just fine if I do it either from withing Visual Studio (2010) itself or using MSBuild just as the build agent would do. (Even on the build machine.)

Just for reference, the code looks something like this:

 public ISet<Task> Tasks {get; set;}

 public IEnumerable<GradedTask> FindGradedTasks(){  
    return Tasks.Select(GetResult).Where(t=>t.HasResult).ToList(); // error   
 }

 public GradedTask GetResult(Task task) {  
    return new GradedTask(this, task);  
 }

Anyone seen anything like this before? What might be causing this behaviour?

Ola Herrdahl
  • 4,216
  • 3
  • 29
  • 23
  • Have you defined your own `Select` extension method? This error can happen if you have and it is being resolved instead of the Linq version. – adrianbanks Nov 24 '10 at 11:07
  • check msbuild version in project build configuration. Did you install .NET 4 on server? – Sergey Mirvoda Nov 29 '10 at 19:32
  • @Sergey I have even tried the command line runner and pointed it at C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe directly. But it just gives me the same error as with the MSbuild runner. I have also tried installing team city on a new machine but that did not work either. – Ola Herrdahl Nov 30 '10 at 11:05
  • And yes, .NET 4 is installed. – Ola Herrdahl Nov 30 '10 at 11:08
  • Also check ToolsVersion property in msbuild task. – Sergey Mirvoda Nov 30 '10 at 12:21
  • I encountered the same problem with a .net 3.5 app. VS2010 seems happy to infer the params but TeamCity isn't. I have just explicity specified them rather than making TeamCity do a .net 4 build. This question touches on the differences between the inference that is possible in each version: http://stackoverflow.com/questions/3063915/linq-extention-selectmany-in-3-5-vs-4-0 – stephen Apr 11 '11 at 11:51

1 Answers1

2

Seems like you are using ISet interface but it is defined only in .NET 4.0

TeamCity is absolutely right. It is VS bug. We are has been beaten by this. Accidentally Reshaper introduce Optional argument. And VS compiles this just fine. But TeamCity is not.

Sergey Mirvoda
  • 3,209
  • 2
  • 26
  • 30
  • Actually I'm using ISet from Iesi.Collections.Generic (NHibernate). But you might still be on to something here... – Ola Herrdahl Nov 30 '10 at 14:18
  • 1
    Changing the settings to: MSBuild version: Microsoft .NET Framework 4.0 MSBuild ToolsVersion: 4.0 Did solve my problem! – Ola Herrdahl Dec 30 '10 at 14:59