The following test that was working with EF 4.2 now throws the next exception with EF 4.3
System.ArgumentException : Type to mock must be an interface or an
abstract or non-sealed class. —-> System.TypeLoadException :
Method ‘CallValidateEntity’ on type ‘Castle.Proxies.DbContext43Proxy’
from assembly ‘DynamicProxyGenAssembly2, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null’ is overriding a method that is
not visible from that assembly.
[Test]
public void CanCreateMoqTest()
{
// Arrange
Mock<DbContext43> mock;
// Act
mock = new Mock<DbContext43>();
// Assert
Assert.NotNull(mock.Object);
}
public class DbContext43:DbContext
{
}
What should I do? Create an interface for my DbContext43?
Is this a breaking change between 4.2 and 4.3?
Thanks!!
Thanks for finding this. The problem is caused by the the InternalsVisibleTo attributes that we stripped out of the EF 4.2 release but left in for the EF 4.3. This allowed Moq (which we use for our tests) to see the internals of EntityFramework.dll. However, since your assembly cannot see those internals you ended up with the exception.
We plan to do a patch release of EF 4.3 in the next few weeks and will be stripping InternalsVisibleTo out of this release after which mocking should work again.
Update: This is now fixed in EF 4.3.1 (and EF 5.0-beta1) released today. Update your NuGet package to get the fix. See http://blogs.msdn.com/b/adonet/archive/2012/02/29/ef4-3-1-and-ef5-beta-1-available-on-nuget.aspx for details.