9

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.QueryOver1.SingleOrDefault() at NHibernate.Criterion.QueryOver`1.NHibernate.IQueryOver.SingleOrDefault()

2
  • Do you have a version bin deployed, and another version installed on the server? Commented Dec 22, 2011 at 14:22
  • Hi Sam, my version is 6.3.7.0 that I know for sure. I think the server already has the 6.2.3.0 in the GAC. how could I make it work? Any tips? Commented Dec 22, 2011 at 14:28

3 Answers 3

28

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>
Sign up to request clarification or add additional context in comments.

2 Comments

+ for <remove invariant="MySql.Data.MySqlClient" />
Hi from 2021, your answer still helps people +1
1

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>

Comments

0

As the expection says, you are using two different versions of MySql. Version 6.2.3.0 and version 6.3.7.0. From this point on I can only guess: Maybe you are using a dll built with a different version of MySql (and it allows installation side by side).

3 Comments

hi @Fischermaen, what should I do then? I think the one in the server is running the 6.2.3.0 one. 6.3.7.0 is the copy from my own pc. I tried deleting the Mysql.data from the bin folder and I get YSOD saying the dll is missing.
@RicL: You have to use the same version on your pc as on the server. That is the only solution.
does it mean I need to get the 6.2.3.0 mysql.data and put it in my project?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.