【发布时间】:2012-05-02 01:49:13
【问题描述】:
我创建了一个新项目(C# 中的 Web 项目)。 在我的项目中创建了一个名为 App_Code 的新文件夹。 然后,我继续添加一个具有以下内容的类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Shipper.DataLayer;
namespace Shipper.BusinessLayer
{
public static class BL
{
public static int JustSomeTest()
{
return 1;
}
}
}
在我的一个页面default.aspx 后面的代码中我试图做:
int i = BL.JustSomeTest();
当我输入 BL. 时,我没有得到任何智能感知。它说我缺少一个程序集或参考。或者它会说The name BL does not exist in the current context。
但是如果类文件在同一个项目中,我是否必须包含参考?我什至尝试构建我的项目,它首先生成了一个 dll 文件,其名称为我的解决方案文件 Shipper.dll,但一旦我添加此引用,它就会显示为 The name BL does not exist in the current context。
在我的 default.aspx 页面中,我尝试添加一条 using 语句
using Shipper.
但只要我这样做,我的命名空间 BusinessLayer 就不会显示... 我很困惑?
编辑
这里是default.aspx:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Shipper.BusinessLayer;
namespace Shipper
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetDefaults();
int i = BL.JustSomeTest();
}
}
}
}
这是我的BL.cs 文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Shipper.DataLayer;
namespace Shipper.BusinessLayer
{
public static class BL
{
public static int JustSomeTest()
{
return 1;
}
}
}
错误为The type or namespace nameBusinessLayerdoes not exist in the namespace Shipper (are you missing an assembly reference)?
【问题讨论】:
-
你的方法是在类之外定义的。
-
你能用aspx中的调用代码更新你的答案吗?
-
@Shedal 这是我的一个错误,我再次编辑了问题。
-
您是否尝试过清除解决方案并全部重建?
-
@Steve 清除解决方案是什么意思。我已经完成了构建->清洁解决方案和构建->构建解决方案。如果我在命名空间的 app_code 文件夹中有一个类,是否需要将其添加为参考?