C# asp.net - 类型或命名空间名称“Helper”无法找到(您是否缺少 using 指令或程序集引用?)

发布于 2024-09-13 01:25:00 字数 926 浏览 5 评论 0原文

我正在重写别人的代码,他们有一个辅助类,里面有很多不应该存在的代码(数据访问、业务逻辑,所有东西都慢慢地被塞进去了)。

我已将相关代码移至适当的预先存在的类中,并在适当的项目中创建了一个单独的全新帮助程序类,但我对此类的所有引用根本不起作用。

这是我的班级外观的简单视图(名称略有更改);

namespace Company.Web.Application.Reporting 

{
    public class ReportHelper
    {
    here I have a bunch of methods
    }
}

这是它的引用方式;

using Company.Web.Application.Reporting;

namespace Company.Web.Application.App.Reports
{
    public partial class PlansReports : PageBase
    {
        //This is the problem part
        private ReportHelper Helper = new ReportHelper(); 
        heaps of other code with no problems here...
    }
}

我的问题是,在我尝试访问新助手的任何地方都会收到以下错误。

类型或命名空间名称 找不到“ReportHelper”(是 你缺少一个 using 指令或 装配参考?)

我所有的 using 语句都在那里,我在每个相关项目中都有适当的引用,但这仍然存在。 此时我完全陷入困境,我只需要解决这个引用问题,这样我就可以确保我的所有辅助方法都能正常工作。

非常感谢任何帮助,

帕特。

I'm reworking someone else's code, where they had a helper class with way to much code that shouldn't be there (data access, business logic, everything had slowly been shoved in there).

I've moved the relevant code into the appropriate pre-existing classes and created a separate, brand new helper class in the appropriate project, but all my references to this class simply don't work.

Here's a simple view of how my class looks (names slightly changed);

namespace Company.Web.Application.Reporting 

{
    public class ReportHelper
    {
    here I have a bunch of methods
    }
}

and here is how it is being referenced;

using Company.Web.Application.Reporting;

namespace Company.Web.Application.App.Reports
{
    public partial class PlansReports : PageBase
    {
        //This is the problem part
        private ReportHelper Helper = new ReportHelper(); 
        heaps of other code with no problems here...
    }
}

My problem is that the I get the following error, everywhere that I try to access my new helper.

The type or namespace name
'ReportHelper' could not be found (are
you missing a using directive or an
assembly reference?)

All my using statements are there, I have the appropriate references in each relevant project, yet this still persists.
At this point I am totally stuck, I just need to get this referencing issue sorted out so I can ensure all my helper methods work correctly.

Any help is greatly appreciated,

Pat.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烈酒灼喉 2024-09-20 01:25:00

好的,我发现了问题(实际上是同事发现的)

这个原始的 Helper 类包含在我的主项目的 app_code 文件夹中,正如我刚刚了解到的,它以与项目中所有其他文件夹不同的方式处理编译。
这里的代码是在运行时编译的,而不是在构建期间编译的。
当我创建新类时,它们位于 app_code 文件夹中,因为我使用 code rush 将类提取到新文件中,这将其保留在同一位置......之后我将它们移动到“合理”位置。
不幸的是,他们仍然继承了以前在 app_code 文件夹中的存在的“Content”构建操作。
因此,在新的类文件上,我只是将其构建操作更改为“编译”,现在一切都很好。

干杯,

帕特。

OK, I found the problem (actually a colleague did)

This original Helper class was contained in the app_code folder of my main project, which as I have just learned, handles compiling differently to all other folders in a project.
Code in here is compiled at run time, rather than during the build.
When I created my new classes, they were in the app_code folder because I used code rush to extract the class to a new file, which kept it in the same location...after which I moved them to their "sensible" location.
Unfortunately they still had the build action of "Content" inherited from their previous presence in the app_code folder.
So, on the new class file, I simply changed its build action to "Compile" and now all is well with the world.

Cheers,

Pat.

も让我眼熟你 2024-09-20 01:25:00

您的 ReportHelper 是否位于单独的项目或 DLL 中?如果是这样,您是否添加了此项目/dll 作为参考? (在解决方案资源管理器中的“参考”下,检查您的项目/dll 是否在那里。

Is your ReportHelper in a separate project or DLL? If so have you added this project/dll as a reference? (In your solution explorer under References, check your project/dll is there.

葬シ愛 2024-09-20 01:25:00

您是否构建了 Company.Web.Application.Reporting 以便了解类型?这将是我的想法,同时确保正确设置依赖项。

Have you built Company.Web.Application.Reporting so that the type would be known? That would be my idea along with ensuring that the dependencies are set up properly.

明明#如月 2024-09-20 01:25:00

听起来你知道自己在做什么,而且一切看起来都很正确,所以它必须是简单的事情。您是否试图访问 ReportHelper 中尚未编译到 dll 中的更改?我会尝试重建参考组件;每次对该程序集进行更改时,都需要重新构建它。

还要验证您是否将正确的程序集(例如调试与发布)添加到项目中。哪种类型并不重要,但您不想将新的更改编译到 Debug dll 中,而不断添加旧版本的 Release dll。

It sounds like you know what you are doing and everything looks right, so it has to be something simple. Are you trying to access changes in ReportHelper that haven't been compiled into the dll? I would try rebuilding the reference assembly; every time you make changes to that assembly, it needs to be rebuilt.

Also verify you are adding the correct assembly (e.g. Debug vs. Release) to your project. It doesn't matter which type, but you don't want compile new changes into the Debug dll, and keep adding the old version of the Release dll.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文