Mono在Linux上找不到System.Data.dll

3

我正在尝试使用dmcs(和gmcs,我都试过了)编译以下示例代码,该示例代码来源于这里

using System;
using System.Data;
using Mono.Data.Sqlite;

public class Example
{

    static void Main() 
    {
        string cs = "URI=file:test.db";

        using( SqliteConnection con = new SqliteConnection(cs))
        {

            con.Open();

            DataTable table = new DataTable("Friends2");

            DataColumn column;
            DataRow row;

            column = new DataColumn();
            column.DataType = System.Type.GetType("System.Int32");
            column.ColumnName = "Id";
            table.Columns.Add(column);

            column = new DataColumn();
            column.DataType = Type.GetType("System.String");
            column.ColumnName = "Name";
            table.Columns.Add(column);

            row = table.NewRow();
            row["Id"] = 1;
            row["Name"] = "Jane";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Id"] = 2;
            row["Name"] = "Lucy";
            table.Rows.Add(row);

            row = table.NewRow();
            row["Id"] = 3;
            row["Name"] = "Thomas";
            table.Rows.Add(row);

            string sql = "SELECT * FROM Friends2";

            using (SqliteDataAdapter da = new SqliteDataAdapter(sql, con))
            {
                using (new SqliteCommandBuilder(da))
                {
                    da.Fill(table);
                    da.Update(table);
                }
            }

            con.Close();
        }
    }
}

我尝试使用以下CL参数进行编译:

dmcs sqlite8.cs -r:Mono.Data.Sqlite.dll, System.Data.dll
gmcs sqlite8.cs -r:Mono.Data.Sqlite.dll, System.Data.dll

以下错误会出现:

sqlite8.cs(2,14): error CS0234: The type or namespace 'Data' does not exists in the namespace 'System'. Are you missing an assembly reference?

或者

error CS2001: Source file 'System.Data.dll' could not be found
Compilation failed: 1 error(s), 0 warnings

那么Mono无法找到System.Data参考。我该怎么办来解决这个问题?我习惯于使用C#,但CLI Mono编译对我来说是新的。


3
点赞了。如果你要给负评,亲爱的读者,请解释为什么。这是一个非常容易理解的问题。 - Mike S
1个回答

5

您不能在单个-r选项中传递多个程序集,必须为每个引用提供-r,例如:

mcs sqlite8.cs -r:Mono.Data.Sqlite.dll -r:System.Data.dll

请注意错误提到了“源文件”。

1
赢家赢家,鸡晚餐。谢谢! - nerdenator
4
你可以传递多个程序集。但是,在逗号分隔符后面不能留有空格。 - Reimer Behrends
感谢Jester提供的答案。 - Niklas Rosencrantz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接