----------------------------------------------------
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;}
檔案判斷:
gbooleang_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的代碼,怎麼覺得應該是他的問題。