【发布时间】:2012-07-18 00:57:45
【问题描述】:
我有 ASP.net 网站。在App_Code 文件夹中,我有具有扩展方法的类。从 Visual Studio 运行此站点时,一切正常。但是在我的 IIS 7 服务器上,我收到以下错误:
CS1061:“System.Data.SqlClient.SqlDataReader”不包含“SafeGetString”的定义,并且找不到接受“System.Data.SqlClient.SqlDataReader”类型的第一个参数的扩展方法“SafeGetString”(是您缺少 using 指令或程序集引用?)
但包含此扩展方法的文件位于 App_Code 文件夹中。我错过了什么重要的东西吗?
ExtentionMethods 类:
public static class ExtentionMethods
{
public static string SafeGetString(this SqlDataReader reader, int colIndex)
{
if (!reader.IsDBNull(colIndex))
return reader.GetString(colIndex);
return "NULL VALUE";
}
public static int SafeGetInt32(this SqlDataReader reader, int colIndex)
{
if (!reader.IsDBNull(colIndex))
return reader.GetInt32(colIndex);
return -1;
}
public static DateTime SafeGetDateTime(this SqlDataReader reader, int colIndex)
{
if (!reader.IsDBNull(colIndex))
{
try
{
}
catch
{
return new DateTime(1800, 1, 1);
}
}
return new DateTime(1800, 1, 1);
}
}
【问题讨论】:
-
是app_code文件夹的父文件夹还是子目录?
-
您可能遗漏了一件重要的事情,那就是最好使用 Web 应用程序项目而不是网站。在许多情况下,网站的行为都很奇怪,也许包括这个。
-
@seeker:那么这可能会有所帮助:stackoverflow.com/questions/155105/…
-
@TimSchmelter 谢谢!为我工作。