简体   繁体   English

C# 错误 CS024 找不到类型或命名空间名称“Form1”(您是否缺少 using 指令或程序集引用?)

[英]C# Error CS024 The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?)

I am fairly new to C# and I run into this error despite the number of remedies I have tried.我对 C# 相当陌生,尽管我尝试了很多补救措施,但还是遇到了这个错误。 I am using a form..我正在使用表格..

The error states:错误指出:

Error CS0246 The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?)错误 CS0246 找不到类型或命名空间名称“Form1”(您是否缺少 using 指令或程序集引用?)

My code looks like:我的代码看起来像:

    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();
            }

My design code looks like this (Form1 is underlined with red):我的设计代码如下所示(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());
        }
    }
}

As Hans Passant mentioned your Form1 class is in the Timer2 namespace.正如 Hans Passant 提到的,您的Form1类位于Timer2命名空间中。

You can fix this by either您可以通过以下任一方式解决此问题

  • use the fully qualified namespace to instaniatate Form1使用完全限定的命名空间来实例化Form1

     Application.Run(new Timer2.Form1());
  • add an using statement for the Timer2 namspace to your Program classTimer2 namspace 的using语句添加到您的Program

    namespace WindowsFormsApp1 { using Timer2; static class Program {
  • or change the namespace in your Form1 class或更改Form1类中的命名空间

    namespace WindowsFormsApp1 { public partial class Form1 : Form {

    but then you have to make sure to do the same in the Form1.Designer.cs file also.但是你必须确保在Form1.Designer.cs文件中也做同样的事情

In my case I had:就我而言,我有:

Referenced DLL : .NET 4.6引用的 DLL:.NET 4.6

Project : .NET 4.5项目:.NET 4.5

Because of the above mismatch, the 4.5 project couldn't see inside the namespace of the 4.6 DLL.由于上述不匹配,4.5 项目无法看到 4.6 DLL 的命名空间内部。 I recompiled the DLL to target .NET 4.6 and I was fine.我重新编译了 DLL 以针对 .NET 4.6,我很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# 错误:错误 CS0246 找不到类型或命名空间名称“”(您是否缺少 using 指令或程序集引用?) - C# Error: Error CS0246 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?) C# 错误 CS0246 找不到类型或命名空间名称“Socket”(您是否缺少 using 指令或程序集引用) - C# error CS0246 The type or namespace name 'Socket' could not be found (are you missing a using directive or an assembly reference) c#错误1找不到类型或名称空间名称”(是否缺少using指令或程序集引用?) - c# Error 1 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246 找不到类型或命名空间名称“CreateRandomAnswersForKey”(您是否缺少 using 指令或程序集引用?)? - Error CS0246 The type or namespace name 'CreateRandomAnswersForKey' could not be found (are you missing a using directive or an assembly reference?)? 错误 CS0246:找不到类型或命名空间名称“Npgsql”(您是否缺少 using 指令或程序集引用?) - error CS0246: The type or namespace name 'Npgsql' could not be found (are you missing a using directive or an assembly reference?) 错误CS0246找不到类型或名称空间名称“ Windows”(是否缺少using指令或程序集引用?) - Error CS0246 The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246:找不到类型或命名空间名称“StreamingContext”(是否缺少 using 指令或程序集引用?) - Error CS0246: The type or namespace name 'StreamingContext' could not be found (are you missing a using directive or an assembly reference?) CS0246:找不到类型或名称空间名称“ T”。 您是否缺少using指令或程序集引用? 在C#中 - CS0246: The type or namespace name `T' could not be found. Are you missing a using directive or an assembly reference? in c# 错误 CS0246:找不到类型或命名空间名称“IWebHostEnvironment”(您是否缺少 using 指令或程序集引用?) - error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246:找不到类型或命名空间名称“BannerPosition”是否缺少 using 指令或程序集引用? - error CS0246: The type or namespace name 'BannerPosition' could not be found are you missing a using directive or an assembly reference?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM