Using .NET Web API (.NET 4, EF 4) and I'm getting some strange errors when debugging and really can't figure what is going on.
Say in the DocumentRepository
I have this constructor:
public DocumentRepository(DocPortalContext db)
{
this._db = db;
}
If I debug and hover over _db
and drill into the items in the popup window I'm coming across the following errors:
System.Data.Entity.Infrastructure.IObjectContextAdapter.ObjectContext = 'System.Data.Entity.DbContext' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Data.Entity.DbContext' could be found (are you missing a using directive or an assembly reference?)
and
System.Collections.Generic.ICollection>.IsReadOnly = 'System.Collections.Generic.Dictionary' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Collections.Generic.Dictionary
No exceptions are being caught.
If I put a break point on this line in a repository method - return _db.Documents.AsQueryable();
- and hover over Document
I get the following error:
System.Linq.IQueryable.Provider = 'System.Data.Entity.Infrastructure.DbQuery' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Data.Entity.Infrastructure.DbQuery' could be f...
Some help would be much appreciated.
Additional information:
Drilling into _db
in the following way gives message quoted at the end:
base(System.Data.Entity.DbContext) -> Internal Context -> _appConfig -> and finally Default Connection Factory has the following error beside it "The function evaluated requires all threads to run."
More information as per my comment:
This isn't really related to the question, but it has me thinking there could be something wrong with my install of .NET or VS - I don't know enough about the pipework to make that call, maybe one of you can. Anyway, I can browse to a URI in my WebAPI project and get JSON returned in the browser. When I try to consume the URI in my Website project, I get this in my browser: Could not find file 'C:\Program Files (x86)\IIS Express\System.Net.Http.StreamContent'.
which is also caught as an exception.
By default EF 4 generates proxy classes on the fly that inherit from your POCO classes or your model first classes. That is most likely why you get these errors on runtime. The odd things is that all required usings should be included.
Are you sure you reference System in your POCO classes (presuming you have POCO classes)?
Do all projects in your solution have the same .NET version setup in project's properties? Do those versions agree with the version on the MSDN describing the missing classes?
Try registering your entity-framework
dll and sql-server
dll in global assembly cache using gacutil.exe
from visual studio command prompt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With