Bug #12871 Not working under Mono on linux
Submitted: 30 Aug 2005 9:52 Modified: 27 Mar 2008 15:15
Reporter: Dimitris Tavlikos Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S4 (Feature request)
Version:1.0.5 OS:Linux (FC3)
Assigned to: CPU Architecture:Any

[30 Aug 2005 9:52] Dimitris Tavlikos
Description:
I cannot use the connector in Mono under linux, because there are some windows API calls to ws2_32.dll. It now only works under Windows.

How to repeat:
Just refererence the connector in a mono .net project, compile the program and try to run it. The program executes, but a "DLLNotFound" exception occurs that points to "ws2_32.dll".

Suggested fix:
2 suggestions:

1. Remove the windows API calls (I don't think so, but it worked perfectly on both platforms before)

2. Add the equivalent p/invoke for linux.
[8 Sep 2005 6:14] Brion Vibber
Here's a test program to reproduce the bug. If successful it should run with no output, or perhaps show a sensible connection error.

using System.Data;

// Fails with MySQL Connector/NET 1.0.5
// Works with an older version dated January 20, 2005
// mcs -r:System.Data -r:MySql.Data.dll Test.cs
using MySql.Data.MySqlClient;

// Works with ByteFX shipped with Mono
// mcs -r:System.Data -r:ByteFX.Data Test.cs
//using ByteFX.Data.MySqlClient;

public class MainClass {
	public static void Main(string[] args) {
		string connstr = "server=localhost;uid=root";
		MySqlConnection db = new MySqlConnection(connstr);
		db.Open();
		db.Close();
	}
}

With MySQL Connector/NET 1.0.5 on Linux or Mac OS X with Mono 1.1.8, I get a failure like this:
Unhandled Exception: MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts ---> System.DllNotFoundException: ws2_32.dll
in (wrapper managed-to-native) MySql.Data.Common.NativeMethods:ioctlsocket (intptr,uint,uint&)
in <0x0005b> MySql.Data.Common.SocketStream:Connect (System.Net.EndPoint remoteEP, Int32 timeout)
in (wrapper remoting-invoke-with-check) MySql.Data.Common.SocketStream:Connect (System.Net.EndPoint,int)
in <0x000f1> MySql.Data.Common.StreamCreator:CreateSocketStream (System.Net.IPAddress ip, Int32 port, Boolean unix)
in <0x002e3> MySql.Data.Common.StreamCreator:GetStream (Int32 timeOut)
in <0x00176> MySql.Data.MySqlClient.NativeDriver:Open ()--- End of inner exception stack trace ---

in <0x001c3> MySql.Data.MySqlClient.NativeDriver:Open ()
in <0x00027> MySql.Data.MySqlClient.Driver:Create (MySql.Data.MySqlClient.MySqlConnectionString settings)
in <0x0008d> MySql.Data.MySqlClient.MySqlPool:CreateNewPooledConnection ()
in <0x001b0> MySql.Data.MySqlClient.MySqlPool:GetPooledConnection ()
in <0x0003f> MySql.Data.MySqlClient.MySqlPool:GetConnection ()
in <0x000e9> MySql.Data.MySqlClient.MySqlPoolManager:GetConnection (MySql.Data.MySqlClient.MySqlConnectionString settings)
in <0x00050> MySql.Data.MySqlClient.MySqlConnection:Open ()

Both the libraries in the .NET 1.0 and .NET 1.1 subdirectories seem to have the same result. I was surprised to find this Windows DLL-specific bit as I had used an earlier version successfully on Linux/Mono. Unfortunately I don't have the version number offhand but the library is dated January 20, 2005, and I can still confirm that it works if I copy in that version of MySql.Data.dll.

The Mono web site currently recommends MySQL Connector/NET for MySQL development with Mono at http://www.mono-project.com/MySQL, and MySQL documentation at http://dev.mysql.com/doc/mysql/en/connector-net-installation.html specifically mentions supporting Mono, so it not working is a bit of a surprise.

Is this an intentional, recent shift to abandoning cross-platform support or just a bug? The documentation in the package doesn't mention Mono except for some old notes in the change log saying that it worked as of 0.65.
[27 Mar 2008 15:15] Reggie Burnett
This is no longer the case (and hasn't been for some time)