且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

类型或命名空间名称“LAD”找不到(是否缺少using指令或程序集引用?)

更新时间:2023-11-19 23:04:40

APP_ code 文件夹是ASP.NET中的一个特殊的文件夹中。 ASP.NET将编译类型 APP_ code 进入这实际上是从你的Web应用程序组件分离的组件。这意味着,当你尝试使用这些类型从你的后端code(比如一个MVC控制器),它是无法解决的类型,因为这些类型将有一个生成操作设置为内容。与构建行动,该文件将不会被包含在主应用程序的编译。

The App_Code folder is a special folder in ASP.NET. ASP.NET will compile the types App_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 a Build Action set to Content. With that build action, the file will not be included in the compilation of your main application.

我建议做,是沟使用 APP_ code 因为只修改构建行动编译不会停止ASP.NET动态编译一个 APP_ code 组装,所以你最终暧昧类型(例如,运行时不知道是否使用编译到主应用程序组件类型或动态APP_ code组装。

What I would recommend doing, is ditch using App_Code because simply changing the build action to Compile won't stop ASP.NET dynamically compiling an App_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.