Why does the Using statement give an error even though my type implements IDisposable?

c# entity-framework unit-testing

Question

In my DataAccess project I have the code:

using (TandAEntities dataContext = new TandAEntities())
{
    // Some code
}

This gives no error and works fine.

But in my Unit Test project, I have that same code, but the compiler gives an error; type used in a using statement must be implicitly convertible to 'System.IDisposable'

I checked the definition by pressing F12, and it does indeed implement IDisposable, and has a dispose method.

Am I perhaps missing some references?

1
9
1/23/2013 9:43:36 AM

Accepted Answer

Most likely answer in linked duplicate - missing using System.Data.Linq.

Other options: you have stale DLLs somewhere (i.e. installed in the GAC).

If you can't easily find stale DLL by just looking around and checking GAC - change code to something that uses this type but compiles and debug the test. Check Debug->Windows->Modules for location of the assembly with this type that is actually used.

12
1/23/2013 6:56:05 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow