![](/img/trans.png)
[英]C# Error: Error CS0246 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)
[英]C# Error CS024 The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?)
我對 C# 相當陌生,盡管我嘗試了很多補救措施,但還是遇到了這個錯誤。 我正在使用表格..
錯誤指出:
錯誤 CS0246 找不到類型或命名空間名稱“Form1”(您是否缺少 using 指令或程序集引用?)
我的代碼看起來像:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Timer2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
我的設計代碼如下所示(Form1 帶有紅色下划線):
namespace WindowsFormsApp1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
正如 Hans Passant 提到的,您的Form1
類位於Timer2
命名空間中。
您可以通過以下任一方式解決此問題
使用完全限定的命名空間來實例化Form1
Application.Run(new Timer2.Form1());
將Timer2
namspace 的using
語句添加到您的Program
類
namespace WindowsFormsApp1 { using Timer2; static class Program {
或更改Form1
類中的命名空間
namespace WindowsFormsApp1 { public partial class Form1 : Form {
但是你必須確保在Form1.Designer.cs文件中也做同樣的事情。
就我而言,我有:
引用的 DLL:.NET 4.6
項目:.NET 4.5
由於上述不匹配,4.5 項目無法看到 4.6 DLL 的命名空間內部。 我重新編譯了 DLL 以針對 .NET 4.6,我很好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.