【问题标题】:File in ASP.NET app_code cannot see referenced file that was added to the web applicationASP.NET app_code 中的文件看不到添加到 Web 应用程序的引用文件
【发布时间】:2013-08-14 07:27:17
【问题描述】:

我遇到的问题是我在 app_code 中有一个类文件,它没有看到添加到 Web 应用程序的引用。我将参考文件添加到项目中(特别是 IBM.Data.Informix),并且项目文件夹中的 aspx.cs 页面可以很好地使用“使用 IBM.Data.Informix”。但是,当我将 using 语句添加到类文件时,它找不到它。

关于如何访问 app_code 中的类文件有很多问题,但我一直找不到与此相关的任何信息。我正在使用 VS2012,如果这有什么不同的话。

错误正是您在尝试使用未引用文件时所期望得到的,即使该引用在项目文件夹中的 aspx.cs 文件中有效:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0246: The type or namespace name 'IBM' could not be found (are you missing a using directive or an assembly reference?)

Source Error:
Line 7:  using System.Net.Mail;
Line 8:  using System.Text;
Line 9:  using IBM.Data.Informix;

【问题讨论】:

  • 您特别收到了什么错误?
  • Garrison Neely:我添加了错误,但这正是您在我描述的情况下所期望的。
  • 这是什么类型的项目?网站、网络应用、mvc 应用?
  • 嗯.. 你可以有一个 asp.net 网站、一个 asp.net web 应用程序、一个 asp.net mvc web 应用程序......这是我的问题。检查 app_code 文件夹及其中的文件的编译选项。该文件夹适用于网站,而不是网络应用程序。
  • 将类直接添加到项目中做到了——试图学习从网站(这是我学到的书上说要使用的)过渡到网络应用程序,但有些奇怪差异。如果 VS2012 无法正确使用它们,我不确定为什么 VS2012 将 ASP.NET 文件夹提供给 Web 应用程序的上下文菜单。如果您在此评论中添加答案,我会将其标记为正确,谢谢。

标签: c# asp.net


【解决方案1】:

Jason P 指出,这个问题是我正在使用 App_Code 文件夹,这显然是为网站设计的,而不是像这样的网络应用程序,并且文件夹中的代码无法访问引用。

看起来很奇怪,但是将类文件移动到主文件夹解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-02
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多