Test.MainForm.Dispose(bool):没有适合的方法来覆盖(CS0115)

时间:2020-01-01 09:19:35

标签: c#

我正在编写C#表单应用程序。以下代码是我的“ MainForm.cs”。

using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinFormsChromium
{
public partial class MainForm : Form
{
    public ChromiumWebBrowser browser;

    public void InitBrowser()
    {
        Cef.Initialize(new CefSettings());
        browser = new ChromiumWebBrowser("www.google.com");
        this.Controls.Add(browser);
        browser.Dock = DockStyle.Fill;

        browser.LoadingStateChanged += browser_LoadingStateChanged; 
    }

    private void browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
    {
        if (e.IsLoading == false)
        {
            browser.ExecuteScriptAsync("alert('All Resources Have Loaded');");
        }
    }

    public MainForm()
    {
        InitializeComponent();
        InitBrowser();
    }
}
}

该文件没有问题。我的“ MainForm.Designer.cs”有问题。以下代码是该文件。

namespace Test
{
partial class MainForm
{
    private System.ComponentModel.IContainer components = null;
    protected override void Dispose(bool disposing)
    {
        if (disposing) {
            if (components != null) {
                components.Dispose();
            }
        }
        base.Dispose(disposing);
    }
    private void InitializeComponent()
    {
        this.SuspendLayout();
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(534, 279);
        this.Name = "MainForm";
        this.Text = "Test";
        this.ResumeLayout(false);
    }
}
}

错误是“ Test.MainForm.Dispose(bool):没有适合的方法来覆盖(CS0115)”。我认为问题是“受保护的覆盖无效Dispose(布尔配置)”。我该如何解决?

1 个答案:

答案 0 :(得分:2)

问题出在不同的命名空间

.cs文件具有命名空间echo {"code":"lyz1To6ZTWClDHSiaeXyxg","redirect_to":"http://example.com/client-redirect-uri?code=lyz1To6ZTWClDHSiaeXyxg"} | jq '.code',而Designer.cs文件具有WinFormsChromium

请在.Designer.cs文件中将Test替换为namespace Test,以使namespace WinFormsChromium部分彼此可见