【问题标题】:Mono can't find System.Data.dll on LinuxMono 在 Linux 上找不到 System.Data.dll
【发布时间】:2013-05-22 15:57:18
【问题描述】:

我正在尝试使用 dmcs(和 gmcs...我都尝试过)从 here 编译以下示例:

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 编译对我来说是新的。

【问题讨论】:

  • 赞成。如果您要投反对票,亲爱的读者,请解释原因。这是一个完全可以理解的问题。

标签: c# sqlite mono system.data


【解决方案1】:

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

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

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

【讨论】:

  • 赢家,鸡肉晚餐。谢谢!
  • 您可以传递多个程序集。但是,逗号分隔符后不能有空格。
  • 感谢 Jester 的回答。
猜你喜欢
  • 1970-01-01
  • 2017-11-06
  • 1970-01-01
  • 1970-01-01
  • 2019-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多