Bug #66545 TypeLoadException thrown caused by mismatch in filename
Submitted: 27 Aug 2012 0:44 Modified: 18 Jun 2015 7:44
Reporter: Peter Hultqvist Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.6.5 OS:Linux (Ubuntu 12.10)
Assigned to: Assigned Account CPU Architecture:Any

[27 Aug 2012 0:44] Peter Hultqvist
Description:
Using the mysql.data.dll on Linux, I can add it to a project and compile it.
But when I run it I get a TypeLoadException

mono --debug Server.exe
Unhandled Exception: System.TypeLoadException: A type load exception has occurred.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: A type load exception has occurred.

How to repeat:
Download the connector from:
http://dev.mysql.com/downloads/connector/net/#downloads

Using the mysql.data.dll on Linux, I can add it to a project and compile it.
But when I run it I get a TypeLoadException

mono --debug Server.exe
Unhandled Exception: System.TypeLoadException: A type load exception has occurred.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: A type load exception has occurred.

Suggested fix:
The fix was to change the filename from mysql.data.dll to MySql.Data.dll 

I assume the case sensitivity on the linux filesystem caused the DLL not to be found.

The DLL was downloaded from http://dev.mysql.com/downloads/connector/net/#downloads

My suggestion is that the DLL in the release be named MySql.Data.dll from start to avoid this problem.
[19 Mar 2013 11:43] MySQL Verification Team
Thank you for the report.

1) What is the mono version you use?

  mono --version

2) Have you installed MySql.Data.dll in the GAC similar to below?

  cd path_to_your MySql.Data.dll assembly
  gacutil -i MySql.Data.dll

Reference : http://www.mono-project.com/MySQL

Please let us know.
[20 Mar 2013 16:08] Peter Hultqvist
My system has been updated since the original submission.
The base is Ubuntu 12.10
With the latest mono available from deb repo, the project is build in monodevelop latest.

mono --version

Mono JIT compiler version 3.0.6 (Debian 3.0.6+dfsg-1~exp1~pre1)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            Included Boehm (with typed GC and Parallel Mark)

I did not install any dll:s into the GAC, the dll was copied into the output directory of my project since it was referenced in the project.

I rebuilt the scenario from my description and now got a different error:
$ ls
mysql.data.dll  TestMySql.exe  TestMySql.exe.mdb

$ mono --debug TestMySql.exe
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies.
File name: 'MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies.
File name: 'MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'

The same workaround still works:

$ ln -s mysql.data.dll  MySql.Data.dll
$ mono --debug TestMySql.exe

Hello World!
MySql.Data.MySqlClient.MySqlConnection

My code was:
class MainClass
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            MySql.Data.MySqlClient.MySqlConnection c = new MySql.Data.MySqlClient.MySqlConnection();
            Console.WriteLine(c);
        }
    }
[20 Mar 2013 16:11] Peter Hultqvist
I would add that using the command suggested at http://www.mono-project.com/MySQL
would not work:
$ gacutil -i MySql.Data.dll

Since the name is all lowercase in the download, I would have to do the same fix here.

This might work but I rather keep all my code and dependencies together so nothing will be forgotten when deployed.
$ gacutil -i mysql.data.dll
[18 May 2015 7:44] Chiranjeevi Battula
Hello Peter Hultqvist,

Thank you for the bug report.
Please try with latest versions MySQL Connector / NET 6.9.6.

Thanks,
Chiranjeevi.
[19 Jun 2015 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".