Build/Test Issues

'System.Linq.IQueryable' does not contain definition for 'Where'

Started by craigrichards on 17,633 views

I have a build issue around the following code. For somereason it now can't find the Where extension method.

public IEnumerable<CPIRate> All(Expression<Func<CPIRate, bool>> filter = null)
{
var cpiRates = DB.CPIRates.Include(x => x.Type);

if (filter != null)
{
cpiRates = cpiRates.Where(filter);
}

return cpiRates.ToList();
}

Hi, thanks for sharing this issue.

Can you provide some more information about the workings of the 'Include' method? Is this a custom built extension returning an IQueryable, or a tool from a 3rd party framework?


Cheers,

Remco
Hi Romco,
This method is in System.core in the .net 4.0 framework. Hope that helps.
Hi,

The closest method I can find is http://msdn.microsoft.com/en-us/library/gg696450(v=vs.103).aspx. Is this the one the code is calling?

As this is an entity framework method, I'm wondering if this may be related to an issue with code generated from the database.

Can you please help by answering the following questions?

- Does this appear consistently, or is it intermittent?
- Has NCrunch ever built this project successfully?
- If this solution is being shared across a team with others using NCrunch, do they experience the same issue?
- Have you tried placing NCrunch in compatibility mode for this solution?
- Does the project build correctly if you browse to the workspace NCrunch has created for it (click on failing project in Tests Window, go to Advanced->Browse to workspace), then run MSBuild.exe against the generated project file in this workspace?

I'm not sure if your time permits this - but if there's any chance you can build a reproduction of the issue, I'm certain I can provide a solution to this quickly.


Thanks!

Remco

Edited

The method i am calling is below. I application compiles and runs ok. It looks like the type namespaces are getting messed up somehow.

Yes NCrunch was working ok. I did just upgrade in the last couple of days to the latest and it has stopped working.
No one else in the team is using NCrunch. I am the pusher here.
I did try all the compatability setting and it was still no good.
No the project will not build against the version in the workspace.


public static IQueryable<TSource> Where<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)

CPIRates\Entities\CPIRates.cs (30)#1: Argument 2: cannot convert from 'System.Linq.Expressions.Expression<System.Func<EnergyMarkets.CPIRates.CPIRate,bool>>' to 'System.Func<EnergyMarkets.CPIRates.Persistence.EntityFramework.CPIRate,bool>'

Cheers
Craig
It looks like this is an intermittent issue. I have made a bunch of other unrelated changes and it is now compiling with NCrunch.
Oops, spoke too soon. Another project is failing to build with the following error.

EnergyMarkets\DealCalculations\CPIRatesTests.cs (11)#0: The type or namespace name 'CPIRates' does not exist in the namespace 'EnergyMarkets.CPIRates.Entities' (are you missing an assembly reference?)
I wonder if this may be due to the relationships between the projects involved.

Has NCrunch given you any warnings in regards to assembly referencing? If there is a cross-project dependency that NCrunch hasn't been able to handle (i.e. if you have an absolute project/assembly reference to something in your foreground solution), this can cause some really strange things to happen.

Does a rebuild of your foreground solution, followed by a reset of the NCrunch engine resolve the problem temporarily?

Are you making use of any tools, frameworks, or project file customisations that may manipulate your build process in any way that would be unusual when compared with any of the standard .NET project templates?

Something else that may help to narrow things down ... You mentioned that the problem appeared after upgrading NCrunch to the latest version. Does a downgrade correct the issue? This would help to identify if the problem is some kind of regression or something else that's changed in your codebase.
NCrunch has not gioven me any warnings about assembly referencing. It is a pretty standard project structure and nothing fancy with pre/post build events.

Rebuild of foreground and the a reset od NCruch does nothing useful.

I will try downgrading later on this afternoon.
What I don't understand from the following error is. I browsed to where the EnergyMarkets project is being built by NCrunch. Opened the project and CPIRates correctly does not exist in that namespace. it is in 'EnergyMarkets.CPIRates.Persistence.EntityFramework'. I guess why would this be happening? I did turn off instrumentation and it is still the same.


EnergyMarkets\DealCalculations\CPIRatesTests.cs (11)#0: The type or namespace name 'CPIRates' does not exist in the namespace 'EnergyMarkets.CPIRates.Entities' (are you missing an assembly reference?)
I'm randomly pitching ideas here, as I'm not completely certain of your solution structure :) Is it possible that the compile error only appears cross-project? (for example, it doesn't appear in the project declaring EnergyMarkets.CPIRates.Entities.CPIRates, but instead in another project that uses this type).

I'm wondering if you could take a look at the project file NCrunch has generated in the workspace for the project that is failing. This project file should contain a list of <Reference> tags that are hard assembly references to other projects that NCrunch has built in their own workspaces. This list of references should allow you to lookup which assemblies the project was built against, and subsequently allow you to view the source files used to build these assemblies.

Do the source files look to be correct? Note that you can freely troubleshoot inside the workspaces in order to deduct why the build issue is appearing, as long as you reset the NCrunch engine afterwards to properly re-sync it. If we can find out mechanically why this error is appearing, maybe we can find its cause.
make sure to include this using
using System.Linq

Post a reply

Log in to reply.