You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio 2022报错:找不到类型或命名空间'ImportFilesr'求助

解决“Could not find type or namespace name 'ImportFilesr'”报错

排查与修复步骤

  • 修正构造函数名
    你代码里的构造函数写的是IniFiles(),但类名是ImportFilesr,C#要求构造函数名必须和类名完全一致,这是直接导致编译错误的核心问题之一,立刻把构造函数名改成ImportFilesr()。

  • 检查所有类名引用
    因为中途修改过两次类名,要遍历项目所有文件:包括调用该类的业务代码、XAML(如果是WPF/WinForms项目)、配置文件等,确保所有旧类名的引用都替换成ImportFilesr,没有遗漏。

  • 清理重建项目

    1. 点击VS顶部菜单【生成】→【清理解决方案】
    2. 手动删除项目目录下的bin和obj文件夹
    3. 再点击【生成】→【重建解决方案】
      VS的编译缓存有时会残留旧信息,清理重建能彻底刷新编译状态。
  • 修正代码语法细节
    你提供的代码里还有两处语法错误:

    • 字符串用了中文引号”01.ini“,必须换成英文引号"01.ini"
    • Application.StartupPath需要引用System.Windows.Forms程序集,如果是控制台/ASP.NET等非WinForms项目,换成AppDomain.CurrentDomain.BaseDirectory来获取程序运行目录

修正后的代码示例

public class ImportFilesr
{
    public string FileName; 
    string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "01.ini");
    [DllImport("kernel32")]
    private static extern bool WritePrivateProfileString(string section, string key, string val, string filePath);
    [DllImport("kernel32")]
    private static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);

    // ... 其他自定义代码

    ImportFilesr()
    {
        UpdateFile();
    }
}

内容的提问来源于stack exchange,提问作者Sadenforen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 13:57:09