C# – Turbine with Db4objects.Db4o.Linq.dll gives Unable to load one or more of the requested types exception

asp.net-mvccdb4oturbineunity-container

In my asp.net-mvc application I'm trying to set up Turbine.
The initialization code goes as follows:

public class MvcApplication : TurbineApplication
{
    static MvcApplication()
    {
        ServiceLocatorManager.SetLocatorProvider(() => new UnityServiceLocator());           
    }
}

and I have then a set of registrars comparable to the following one:

public class UserRepositoryRegistration : IServiceRegistration
{
    public void Register(IServiceLocator locator)
    {
        locator.Register<IUserRepository, Db4oUserRepository>();
    }
}

If I try to run, I get the following error somewhere after the SetLocatorProvider, but before entering any of the register methods:

Server Error in '/' Application.

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

    [ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
       System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark) +0
       System.Reflection.Assembly.GetTypes() +105
       MvcTurbine.ComponentModel.DefaultAutoRegistrator.AutoRegister(ServiceRegistration serviceRegistration) +338
       MvcTurbine.Web.RotorContext.ProcessAutomaticRegistration(AutoRegistrationList registrationList) +155
       MvcTurbine.Web.RotorContext.AutoRegistrationForContext() +163
       MvcTurbine.Web.RotorContext.Turn() +37
       MvcTurbine.Web.TurbineApplication.ExecuteContext() +43
       MvcTurbine.Web.TurbineApplication.TurnRotor() +65
       MvcTurbine.Web.TurbineApplication.Application_Start(Object sender, EventArgs e) +85

UPDATE
Narrowed down the problem library to Db4objects.Db4o.Linq.dll
As soon as I have this library as a references (not even "using", just added to references) in one of my libraries that is referenced in my mvc webapplication I get the above mentioned YSOD. All other Db4o libraries work just fine.

METTRE À JOUR
Tried swapping the UnityServiceLocator with the WindsosServiceLocator and the NinjectServiceLocator. Exact same results, so more then likely the problem doesn't originate in either of the libs.

OPPDATERING
To recreate the error page it suffices to take the following steps:

  • Create new Mvc application (doesn't matter wat version)
  • Alter gloabal.asax.cs code to use MvcTurbine and add needed MvcTurbine libs
    You will find everything still works as expected
  • Add Db4objects.Db4o.dll
    Still everything works
  • Add Db4objects.Db4o.linq.dll
    YSOD

Any ideas on where and how to debug this?

Best Answer

For the sake of writing down a proper answer. I think you're getting a TypeLoadException triggered by a failure to load an assembly that is referenced by Db4objects.Db4o.Linq.

Looking at it in ildasm shows that it requires the following assemblies that are shipped with db4o (use the same assemblies that came with Db4objects.Db4o.Linq to avoid any mismatch).

Those assemblies are:

  • Mono.Cecil
  • Cecil.FlowAnalysis

For the record, abd as of today, they're used by the LINQ to db4o query optimizer to analyze properties access in linq queries.