oJM86o
oJM86o

Reputation: 2118

C# web project complaining about a class

I created a new project (web project in C#). Created a new folder in my project called App_Code. I then proceeded to add a class with the following:

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;
        }
    }
}

And in one of my pages default.aspx in the code behind I tried to do:

int i = BL.JustSomeTest();

I am not getting any intellisense when I type in BL.. It says I am missing an assembly or reference. Or it will say The name BL does not exist in the current context. But do I have to include a reference if the class file is in the same project? I even tried to Build my project and it at first generated a dll file with the name of my solution file, Shipper.dll but as soon as I add this reference it says The name BL does not exist in the current context.

In my default.aspx page I've tried to add a using statement

using Shipper.

But as soon as I do that my namespace BusinessLayer is not shown... Im confused?

Edit

Here is 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();
            }
        }
   }
}

Here is my BL.cs file:

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 error reads The type or namespace nameBusinessLayerdoes not exist in the namespace Shipper (are you missing an assembly reference)?

Upvotes: 0

Views: 1238

Answers (7)

Bex
Bex

Reputation: 4918

Try making your class not static but leave your method as static. (only because I never use static classes, but it doesn't appear to make any difference)

Or if you are seriously having problems and can't work it out install a copy of Resharper and it will probably help!

Upvotes: 0

dice
dice

Reputation: 2880

First thing is make sure you have added a reference to the Shipper project, not the shipper DLL.

Then make sure the Shipper project is re-built, best bet to do a clean and build.

Then check your intellisense again, I suspect you are referencin an oleder version of the Shipper dll.

Upvotes: 0

ΩmegaMan
ΩmegaMan

Reputation: 31606

try

using Shipper.BusinessLayer;

Things to try

  1. Verify the namespace is the one you believe it is by viewing the properties of the target project in the solutions explorer.
  2. In Visual Studio use the Object Browser and locate the namespace and verify the class can be seen. If the object browser can't see it, neither can the code.

Upvotes: 0

npclaudiu
npclaudiu

Reputation: 2441

This forum thread on Wrox might be also useful.

Upvotes: 0

npclaudiu
npclaudiu

Reputation: 2441

Try to delete the namespace declaration:

using System;

public static class BL
{
    public static int JustSomeTest()
    {
       return 1;
    }
}

Upvotes: 0

user610217
user610217

Reputation:

your method was outside a class. That's a no-no. Try this instead:

namespace Shipper.BusinessLayer
{
    public static class BL
    {
        public static int JustSomeTest()
        {
            return 1;
        }
    }
}

Also, if you're expecting BL to pop up, make sure the namespace is referenced (using Shipper.BusinessLayer). Why is this a static class, though? I think you probably don't want that unless you're making extension methods.

Upvotes: 2

NSGaga
NSGaga

Reputation: 14302

your...

public static int JustSomeTest()
 {
   return 1;
 }

...is out of the 'class' - you cannot have methods defined for the namespace alone.

(at least from your example, it might be just a typo but then you'd need to give us a working example)

Upvotes: 5

Related Questions