0

注意:这似乎是 MonoDevelop 中相当常见的错误。

我正在更新我编写的 C# Mono 应用程序。我在使用应用程序使用的一些对话框时遇到问题。

例如,在以下代码中:

public partial class Generic : Gtk.Dialog
{
    public Generic (string text, string title = "Error Notice", string label = "<b>Error Details</b>", int height = 150)
    {
        this.Build ();
        textview1.Buffer.Text = text;
        this.Title = "Application - " + title;
        label1.LabelProp = label;
        this.DefaultHeight = height;
        this.Resize(375, this.DefaultHeight);
    }


    protected void OnButtonOkClicked (object sender, System.EventArgs e)
    {
        this.Destroy();
    }
}

我收到这些错误:

Error CS1061: Type `Namespace.Generic' does not contain a definition for `Build' and no extension method `Build' of type `Namespace.Generic' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Namespace)
Error CS0103: The name `textview1' does not exist in the current context (CS0103) (Namespace)

以及 label1 的另一个。问题是 textview1确实存在。那么为什么 MonoDevelop 告诉我它不是我不知道的。

我认为this.Build是继承自 Gtk.Dialog。正确的?

这些以前可以工作,但现在,即使从头开始重新制作对话框并重新输入旧代码以实现功能,它仍然无法工作。

我的旧编译仍然有效,所以虽然我不确定,但这似乎表明 GTK# 工作正常......

任何帮助表示赞赏。谢谢。

4

4 回答 4

2

错误出现在自动生成的类中,出于某种原因,它们没有随着 GUI 的更改而更新。我注意到它们不包含对我的代码中引用的对象的任何引用。我删除了自动生成的类,并重新创建了对话框来解决问题。

于 2012-07-18T23:59:02.517 回答
1

我有什么似乎是同样的问题(我知道这个问题很老)。我遇到的错误是:“cs0103”。我只是通过重建解决方案来解决这个问题。

于 2016-08-29T21:11:53.747 回答
0

我得到了同样的错误,它发生在我重命名 Gtk.Window 类型类时。yourproj/gtk-gui 中的文件也被重命名,但文件中的类的定义没有。只需在里面重命名,并确保在文件中定义了 Build -> Monodevelop 有时在重命名时会丢弃一些代码。

于 2014-11-17T15:18:12.727 回答
0

我有同样的问题。这是因为项目设置的破坏。要解决此问题,请尝试打开 .csproj 文件并添加到<ItemGroup> <Compile Include="gtk-gui\yourUIGeneretedFimename.cs" />

yourUIGeneretedFimename.cs 应该在放置 gui.stetic 文件的文件夹中。gui.stetic 是一个描述 ui 的带有 xml 的文件。

于 2016-10-05T10:47:34.393 回答