类型或命名空间名称“LAD”;无法找到(您是否缺少 using 指令或程序集引用?)
您好,我有一个在 C# 上运行的 ASP Web 应用程序作为其后端,我试图运行它,但网页(在我的盒子上本地运行)给了我错误消息。现在,Web 应用程序尝试引用的命名空间是“using LAD.CDD.NSJ;”它们位于 App_Code 文件夹中。
文件的名称为 Common.cs、Email.cs、Data.cs 和 User.cs。
它们在代码中都有一个名为 LAD.CDD.NSJ 的命名空间。以前的程序员没有将这些文件制作成 dll,而只是将其保留为 .cs 文件。我正在尝试将这些文件用于另一个项目,但不断收到该错误消息。
Hello I have an ASP web application runs on C# as its backend that I'm trying to get running but the webpage (ran locally on my box) gives me the error message. Now the namespace the webapp is trying to reference is "using LAD.CDD.NSJ;" which are located in the App_Code folder.
The name of the files are Common.cs, Email.cs, Data.cs, and User.cs.
They all have a namespace call LAD.CDD.NSJ within the code. The previous programmers didn't make those files into a dll and just kept it as a .cs file. I'm trying to use these files for another project but keep getting that error message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
App_Code
文件夹是 ASP.NET 中的一个特殊文件夹。 ASP.NET 会将App_Code
类型编译为一个程序集,该程序集实际上与您的 Web 应用程序程序集是分开的。这意味着,当您尝试使用后端代码(例如 MVC 控制器)中的这些类型时,它无法解析该类型,因为这些类型的Build Action
设置为Content< /代码>。通过该构建操作,该文件将不会包含在主应用程序的编译中。
我建议做的是放弃使用
App_Code
,因为简单地将构建操作更改为Compile
不会阻止 ASP.NET 动态编译App_Code
程序集,因此您最终会得到不明确的类型(即,运行时不知道是否使用编译到主应用程序程序集中的类型,还是使用动态 App_Code 程序集。将这些文件移动到另一个位置,并设置构建操作(在属性)至
编译
。The
App_Code
folder is a special folder in ASP.NET. ASP.NET will compile the typesApp_Code
into an assembly which is actually separate from your web application assembly. This means, when you try and use those types from your backend code (e.g. an MVC controller), it is unable to resolve the type because those types will have aBuild Action
set toContent
. With that build action, the file will not be included in the compilation of your main application.What I would recommend doing, is ditch using
App_Code
because simply changing the build action toCompile
won't stop ASP.NET dynamically compiling anApp_Code
assembly, so you end up with ambiguous types (i.e., the runtime doesn't know whether to use the type compiled into your main application assembly, or the dynamic App_Code assembly.Move those files to another location, and set the Build Action (in Properties) to
Compile
.