I am getting this strange inexplicable error when I uploaded my application to a server for testing. From what I studied, it seems to be caused by conflicting MySql.Data, the copy I uploaded belongs to: 6.3.7.0.
How could I solve this issue? I thought just putting it in the bin would 'override' the one in GAC?
NHibernate.Exceptions.GenericADOException: could not execute query [ SELECT this_.Id as Id18_0_, this_.Email as Email18_0_,
(etc properties)
FROM User
this_ WHERE this_.Email = ? and this_.Password = ? ] Positional parameters: #0>WvewHQlNRyQNKjBAtPR1AwrWQj0nwfmIflO+r4mCJQWA1jZ9zRvefcGz6ZA69b3v #1>97403BA77F7C26BEC6B4F0A4F8509E02848CCD7DCF61D7DF5D79C3AAB2760E6AE1EB26F5D10D384E069F8C6089C47D3F1F0F17E7EBF30F71A68A39DF8863646F
[SQL: SELECT this_.Id as Id18_0_, this_.Email as Email18_0_,
(etc properties)
FROM User
this_ WHERE this_.Email = ? and this_.Password = ?] --->
System.InvalidCastException: [A]MySql.Data.MySqlClient.MySqlConnection cannot be cast to [B]MySql.Data.MySqlClient.MySqlConnection. Type A originates from 'MySql.Data, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' in the context 'Default' at location 'C:\Windows\assembly\GAC_MSIL\MySql.Data\6.2.3.0__c5687fc88969c44d\MySql.Data.dll'. Type B originates from 'MySql.Data, Version=6.3.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\cb584441\17e039bb\assembly\dl3\6b14fe89\804a4095_b2c0cc01\MySql.Data.DLL'.
at MySql.Data.MySqlClient.MySqlCommand.set_DbConnection(DbConnection value) at System.Data.Common.DbCommand.System.Data.IDbCommand.set_Connection(IDbConnection value) at NHibernate.AdoNet.AbstractBatcher.Prepare(IDbCommand cmd) at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) --- End of inner exception stack trace --- at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet1 querySpaces, IType[] resultTypes) at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) at NHibernate.Impl.CriteriaImpl.List(IList results) at NHibernate.Impl.CriteriaImpl.UniqueResult[T]() at NHibernate.Criterion.QueryOver
1.SingleOrDefault() at NHibernate.Criterion.QueryOver`1.NHibernate.IQueryOver.SingleOrDefault()
I got the same problem but years later!
My server has installed in gac the MySql Connector 6.4.6 version, but I'm working with the 6.8.3 version, I was getting the "cannot be cast error". I fixed it by adding the following section to the .config file
<system.data>
<DbProviderFactories>
<!-- Removes the dll installed in gac-->
<remove invariant="MySql.Data.MySqlClient" />
<!-- Add the dll copied in the bin folder-->
<add name="MySQL" description="ADO.Net driver for MySQL" invariant="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data"/>
</DbProviderFactories>
</system.data>
I had the same issue, conflict between version 18 and 19. Doing this in web.config fixed it. Set the new version to the one you have in your machine.
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.18.0" newVersion="8.0.19.0" />
</dependentAssembly>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With