简体   繁体   中英

HibernateException: Could not create the driver from NHibernate.Driver.MySqlDataDriver

I want to create a connection with MySQL server using FluentNHibernate in ASP.NET Core, but I get an exception.

My Fluent configuration:

var config = Fluently.Configure()
                     .Database(MySQLConfiguration
                         .Standard
                         .ConnectionString(cs => cs
                             .Server(dbServer)
                             .Database(dbName)
                             .Username(dbUsername)
                             .Password(dbPassword)))
                     .Mappings(x =>x.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
                     .BuildSessionFactory();

Exception:

FluentNHibernate.Cfg.FluentConfigurationException: "An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail."

InnerExceptions:

HibernateException: Could not create the driver from NHibernate.Driver.MySqlDataDriver, NHibernate, Version=5.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.

TargetInvocationException: Exception has been thrown by the target of an invocation.

TypeLoadException: Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Project config:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentNHibernate" Version="2.0.3" />
    <PackageReference Include="Iesi.Collections" Version="4.0.2" />
    <PackageReference Include="log4net" Version="2.0.8" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="MySql.Data" Version="6.10.4" />
    <PackageReference Include="MySql.Data.Entity" Version="6.10.4" />
    <PackageReference Include="MySql.Web" Version="6.10.4" />
    <PackageReference Include="NHibernate" Version="5.0.3" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
  </ItemGroup>
</Project>

Link to deps.json : http://pastebin.com/pn67pa6y

What should I do?

FluentNHibernate does not support .NET Core ( issue ), because NHibernate has not ( PR ).

NHibernate PR is scheduled for v5.1 , due by December 15, 2017 at the time of this writing.

mstancombe has a fork for .NET Core, but you have to build it yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM