【问题标题】:The Type or namespace ALMSTWKND could not be found... - but it exists找不到类型或命名空间 ALMTWKND... - 但它存在
【发布时间】:2021-12-24 06:21:44
【问题描述】:

我收到了 20 到 60 个错误说明:

严重性代码描述项目文件行抑制状态 错误 CS0246 找不到类型或命名空间名称“ALMSTWKND”(您是否缺少 using 指令或程序集引用?) App Name C:\Users\realj\Documents\Visual Studio 2019\App Name\GettingStarted.cs 2 Active

但是,我引用了这个 DLL,并且在我的所有代码中都在需要的地方使用了指令。由于有多少文件和使用指令,我无法发布所有代码,但这里有一点:

using App_Name.Properties;
using REDACTED.UI.WindowsForms.Controls;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Media;
using System.Runtime.CompilerServices;

可能很重要的一点是,该项目最近使用 JustDecompile 进行了反编译,因为我丢失了可追溯到 2009 年的原始源代码。

我在 StackOverflow 上看到过其他类似的问题,其中的建议是确保每个项目都针对相同版本的 .NET 框架。我已确保这些项目都针对相同的版本。

代码更新:

using System;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
 
namespace App_Name
{
    internal static class Program
    {
        public static Version version;
 
        public static string appVersion;
 
        public static string AppDataDirectory;
 
        public static string ColorHistoryFilePath;
 
        public static History history;
 
        static Program()
        {
            Program.version = Assembly.GetExecutingAssembly().GetName().Version;
            Program.AppDataDirectory = string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "\\App Name\\");
            Program.ColorHistoryFilePath = string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "\\App Name\\.history");
        }
 
        public static void EnsureAppDataDirectoryExists()
        {
            if (!Directory.Exists(Program.AppDataDirectory))
            {
                Directory.CreateDirectory(Program.AppDataDirectory);
            }
        }
 
        [STAThread]
        private static void Main()
        {
            Program.appVersion = Application.ProductVersion;
            Program.EnsureAppDataDirectoryExists();
            if (History.Exists(Program.ColorHistoryFilePath))
            {
                History.Load(Program.ColorHistoryFilePath);
            }
 
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Window());
        }
    }
}

截图更新:

Exception screenshot

更新: 将 Program.cs 文件中的以下代码行 Application.Run(new Window()); 更改为 Application.Run(new About()); 后,我可以正确打开“关于”对话框。

更新 2: 我通过在 Window.cs 文件中注释掉以下行来使其工作:

    //this.notificationIcon = null;
    //this.notificationIcon.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("notificationIcon.Icon");

【问题讨论】:

  • 你能显示参考资料吗?其中一个是否有黄色感叹号?
  • 我会给你看一张参考图片。没有黄色感叹号:):ibb.co/CJfdcKK
  • 您可以edit您的问题添加信息。链接到外部网站不是一个好主意,很多人不会关注这样的链接。
  • @KlausGütter SO 不允许新手这样做。在我看来对新人的限制太多了,尤其是那些想在适当的时候在 cmets 部分帮助别人的人。
  • 确实,新手不能嵌入图片..我给你改一下

标签: c# .net


【解决方案1】:

通过在 Window.cs 文件中注释掉这些行,我终于让应用程序能够正确构建和运行:

//this.notificationIcon = null;
//this.notificationIcon.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("notificationIcon.Icon");

【讨论】:

    猜你喜欢
    • 2014-04-24
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 2013-03-25
    • 1970-01-01
    • 2017-07-12
    • 2011-05-13
    相关资源
    最近更新 更多