0
votes

I have a simple Entity Framework Code First context for persisting events as they arrive from the bus. The context is :

public class MyContext : DbContext
{
    public MyContext (DbConnection connection)
        : base(connection, false)
    {

        Database.SetInitializer<MyContext>(null);
        Configuration.AutoDetectChangesEnabled = true;
    }

    public DbSet<MyEvent> MyEvents { get; set; }

}

where MyEvent is

public class MyEvent
{
    public int Id { get; set; }

    public string Source { get; set; }

    public string MessageId { get; set; }

    public DateTime EventDate { get; set; }
}

Now, when I try to access the context.MyEvents collection I get a ReflectionTypeLoadException

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

with LoaderException

"Method 'ToCombinedRows' in type 'XXXX' from assembly 'YYYY' does not have an implementation."

Now this is really strange as the type XXXX is completely unrelated to the object being persisted and has no reason to have a method of this name.

All the objects are defined in the same assembly, and I am running from an integration test project, with references CopyLocal set to true. Does anyone know how to get my context to talk to the database?

1

1 Answers

0
votes

Ok, found the problem.

I was running the integration tests using ReSharper, which loads the assembly into a temporary location, and Entity Framework could not work out the types in that location (it was fine when I ran from a Console app). For reasons that I do not know, when I split the context objects into their own assemblies, Entity Framework ran fine. So, not a problem with the references in the project, just a problem loading these references into the test harness.