【问题标题】:monodevelop compling error; why does misses assembly reference if those exists?monodevelop 编译错误;如果存在,为什么会错过装配参考?
【发布时间】:2018-04-11 10:48:05
【问题描述】:

我从 MonoDevelop 制作了一个 GTK# 2.0 项目,它生成了两个文件:

程序.cs

using System;
using Gtk;

namespace Application
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Application.Init();
            MainWindow win = new MainWindow();
            win.Show();
            Application.Run();
        }
    }
}

MainWindow.cs:

using System;
using Gtk;

public partial class MainWindow : Gtk.Window
{
    public MainWindow() : base(Gtk.WindowType.Toplevel)
    {
        Build();
    }

    protected void OnDeleteEvent(object sender, DeleteEventArgs a)
    {
        Application.Quit();
        a.RetVal = true;
    }
}

我按下了“调试”按钮,没有修改任何代码。 然后编译器打印了这个:

The type or namespace name `Init' does not exist in the namespace `Application'. Are you missing an assembly reference? (CS0234)
The type or namespace name `Run' does not exist in the namespace `Application'. Are you missing an assembly reference? (CS0234)
The type or namespace name `Quit' does not exist in the namespace `Application'. Are you missing an assembly reference? (CS0234)

我在解决方案选项卡上看到了参考列表,并且存在 Gtk.Application.Init,Run,Quit。那为什么会出现这个错误呢?

【问题讨论】:

  • 您使用的是什么操作系统?什么版本的 MonoDevelop?您是否安装了所有需要的软件包?我在 Manjaro 上使用 MonoDevelop 7.3.3 和 Mono 5.10。你的设置是什么?无论如何,你需要安装 Gtk#。
  • DragonFlyBSD 上的 MonoDevelop 6.2.1;反正我已经解决了。我将 Application.Init,Run,Quit 编辑到 Gtk.Application.Init,Run,Quit - 这就是解决方法。
  • 如果你的问题是准确的,那么没有解释为什么要放“Gtk”。前缀调用解决了你的问题(你有一个“使用 Gtk;”在类的顶部)。没关系,我很高兴你解决了它。
  • @JihooByeon 如果你解决了,请回答你自己的问题

标签: c# mono gtk monodevelop gtk#


【解决方案1】:

将 Program.cs 修改为:

using System;
using Gtk;

namespace Application
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Gtk.Application.Init();
            MainWindow win = new MainWindow();
            win.Show();
            Gtk.Application.Run();
        }
    }
}

将 MainWindow.cs 修改为:

using System;
using Gtk;

public partial class MainWindow : Gtk.Window
{
    public MainWindow() : base(Gtk.WindowType.Toplevel)
    {
        Build();
    }

    protected void OnDeleteEvent(object sender, DeleteEventArgs a)
    {
        Gtk.Application.Quit();
        a.RetVal = true;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多