Fluent NHibernate cannot load MySql.Data from GAC

2019-03-05 17:04发布

问题:

I got the following code :

    var cfg = new Configuration();
    cfg.Configure();
    FluentConfiguration config = Fluently.Configure(cfg)
        .Mappings(
            m => m.FluentMappings.AddFromAssemblyOf<InputMapping>());
    s_SessionSource = new SessionSource(config);

last line throws exception when I debug my unit test with following error:

Could not load file or assembly 'MySql.Data' or one of its dependencies. The system cannot find the file specified.

problem is it doesn't say what version it did try to use. I tried to catch all versions with following configuration:

 <dependentAssembly>
    <assemblyIdentity name="MySql.Data"
                      publicKeyToken="c5687fc88969c44d"
                      culture="neutral" />
    <bindingRedirect oldVersion="1.0.0.0-6.3.6.0"
                     newVersion="6.3.7.0" />
 </dependentAssembly>

but problem persists. Its pretty odd that exception doesn't say anything about version , it usually does in such cases.

Fluent NHB is latest 1.2 for 3.1 version NHB is 3.2 connector is 6.3.7.0

I am using MSTest. When I run test without debug (Run Checked Test) it doesn't throw any exceptions and completes successfully ( it does perform manipluations with MySQL test database so in that case it finds MySql.Data.dll and inserts row for example with no problems).

UPDATE okay when I took MySql.Data.dll from GAC and referenced it as a file, and setup Copy Local it finally started to work in debug. What is the case? Why it cannot load it from GAC in debug, and can in simple run mode?

回答1:

Perhaps a problem with 32/64 bits execution configuration? The DLL is the same for both platforms, but the .exe is not. You could check if your test project is configured to AnyCPU.