*nix mono 找不到 MySql.Data Could not be loaded

时间:2021-01-31 04:12:10

----------------------------------------------------

2010-05-30 更新:

最初遇到这个问题的时候,想到了由于unix系统的原因文件名大小写敏感导致了这个问题,这段时间看mono的源代码,找到的源码所在,更直观一些。

mono的底层库用的最开始用的是eglibc,访问文件正式用的这个库。当然,unix标准的库,大小写肯定不能放过。

 

加载程序集:

 

static MonoAssembly *
real_load (gchar **search_path, const gchar *culture, const gchar *name, gboolean refonly)
{
	MonoAssembly *result = NULL;
	gchar **path;
	gchar *filename;
	const gchar *local_culture;
	gint len;
	gboolean is_private = FALSE;

	if (!culture || *culture == '\0') {
		local_culture = "";
	} else {
		local_culture = culture;
	}

	filename =  g_strconcat (name, ".dll", NULL);
	len = strlen (filename);

	for (path = search_path; *path; path++) {
		if (**path == '\0') {
			is_private = TRUE;
			continue; /* Ignore empty ApplicationBase */
		}

		/* See test cases in bug #58992 and bug #57710 */
		/* 1st try: [culture]/[name].dll (culture may be empty) */
		strcpy (filename + len - 4, ".dll");
		if (try_load_from (&result, *path, local_culture, "", filename, refonly, is_private))
			break;

		/* 2nd try: [culture]/[name].exe (culture may be empty) */
		strcpy (filename + len - 4, ".exe");
		if (try_load_from (&result, *path, local_culture, "", filename, refonly, is_private))
			break;

		/* 3rd try: [culture]/[name]/[name].dll (culture may be empty) */
		strcpy (filename + len - 4, ".dll");
		if (try_load_from (&result, *path, local_culture, name, filename, refonly, is_private))
			break;

		/* 4th try: [culture]/[name]/[name].exe (culture may be empty) */
		strcpy (filename + len - 4, ".exe");
		if (try_load_from (&result, *path, local_culture, name, filename, refonly, is_private))
			break;
	}

	g_free (filename);
	return result;
}


文件判断:

 

 

gboolean
g_file_test (const gchar *filename, GFileTest test)
{
	struct stat st;
	gboolean have_stat;

	if (filename == NULL || test == 0)
		return FALSE;

	have_stat = FALSE;

	if ((test & G_FILE_TEST_EXISTS) != 0) {
		if (access (filename, F_OK) == 0)
			return TRUE;
	}

	if ((test & G_FILE_TEST_IS_EXECUTABLE) != 0) {
		if (access (filename, X_OK) == 0)
			return TRUE;
	}
	if ((test & G_FILE_TEST_IS_SYMLINK) != 0) {
		have_stat = (lstat (filename, &st) == 0);
		if (have_stat && S_ISLNK (st.st_mode))
			return TRUE;
	}

	if ((test & G_FILE_TEST_IS_REGULAR) != 0) {
		if (!have_stat)
			have_stat = (stat (filename, &st) == 0);
		if (have_stat && S_ISREG (st.st_mode))
			return TRUE;
	}
	if ((test & G_FILE_TEST_IS_DIR) != 0) {
		if (!have_stat)
			have_stat = (stat (filename, &st) == 0);
		if (have_stat && S_ISDIR (st.st_mode))
			return TRUE;
	}
	return FALSE;
}

 

------------------------------------------------------------

 

今天尝试着在linux下面用mono访问MySql。

官方提供了ADO.NET Driver for MYSQL (http://www.mysql.com/downloads/connector/net/).其中东西很简单,几个dll文件,以及一个MSDN样式的CHM文档文件。

 

运行程序的时候总是有问题,提示信息:

 The following assembly Referenced from Test.exe could not be loaded:
     Assembly:   MySql.Data    (assemblyref_index=1)
     Version:    6.2.3.0
     Public Key: c5687fc88969c44d

 The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly

 

 但是我明明已经添加好了引用,而且目录中有官方提供的mysql.data.dll.试了几次都不行,于是猜测是不是文件明的问题,因为*nix下文件名大小写敏感。改成MySql.Data.dll了之后,居然就好了

 

不知道这个问题算什么问题,哪天看看mono的代码,怎么觉得应该是他的问题。