Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie: "missing using directive or assembly reference" 1

Status
Not open for further replies.

LFCfan

Programmer
Nov 29, 2002
3,015
0
0
GB
Hi folks

(Web application, with sql server 2000 back end.)

I’m very new at all this, so your patience is required!

I had a solution (MySolution) with two projects – WebLayer and BusinessLayer. BusinessLayer had all the data access classes in it as well as the business objects, and I decided to put the .cs data access files into a new project (class library), DataAccessLayer. All objects were under the MySolution.BusinessLayer namespace, so when I moved the data access objects, I put them under a MySolution.DataAccessLayer namespace.

I have added a reference to the DataAccessLayer in the BusinessLayer project. The problem is, the BusinessLayer doesn’t recognise the MySolution.DataAccessLayer namespace, and complains when I put a using directive in (ie, blue squiggly line in VS). When I try to build the DataAccessLayer project (and if I’m not wrong, this is when the MySolution.DataAccessLayer dll is created…?) I get lots of these errors –

“the type or namespace name ‘MyClass’ could not be found (are you missing a using directive or an assembly reference?)”

where MyClass is any class in the DAL.

So I can’t build the project because of the namespace in the using directive not being recognised, and without building the project, the assembly reference won’t appear.

I’m very confused – I don’t see why the DAL namespace is not recognised – as far as I can tell, I have created the DAL in exactly the same fashion as the BL (including setting the attribute values in the DAL’s AssemblyInfo.cs file)

I have been all over tek tips and google and cant find anything that seems to help.

If anyone can shed some light on this, I would very much appreciate it – I’m most likely missing something obvious! I hope all this makes sense, I will of course try to clarify further anything that isn’t.

Many thanks in advance.
 
I'll give you a brief run down on namespaces/classes covering some stuff you must know, but I wouldn't want to leave something out.

For all practical purposes, imo, a dll file equals a namespace. System.dll = System namespace, System.Web.dll = System.Web namespace and so on.

A namespace contains classes, structs, enumerations, delegates and probably a few other things. That means your general code should look like:

File 1: MySolution.WebLayer.dll
Code:
using System;
namespace MySolution.WebLayer.dll
{
struct myStruct
{
}

class ClassMine
{
}
}

File 2: MySolution.DataAccessLayer.dll
using System.dll;
namespace MySolution.DataAccessLayer.dll
{
class allyerclassesareebelongtous
{
}
}

File 3: MySolution.BusinessLayer.dll
using MySolution.DataAccessLayer;
using System.dll;
using MySolution.WebLayer;
namespace MySolution.BusinessLayer
{
public class thereisnospoon
{
public reality Matrix()
{
return new Reality();
}
}

Now you have to make sure that MySolution.BusinessLayer.dll knows where to find WebLayer and DataAccessLayer! This still screws me up sometimes! See, all the microsoft namespaces, System, System.Threading, System.Web.UI.WebControls and all those are usually registered by installing the .net framework. However, when you use your own namespaces, you have to tell the compiler WHERE to find the dll files. For all the compiler knows, these other dll files are in Istanbul on a web server. I'm not sure how you do this in VisualStudio. I don't use it. If you use the command line compiler like I do (batch file), then you have to specify the paths of all your dll files using the assemblies switch.(maybe another? I've used my batch file so long I forget)

At any rate, that's the rundown on namespaces, dll files, classes and the matrix.

LATE
 
* Just thought of something.

Make sure you aren't having a brain sneeze. Are you SURE that you are using all the namespaces you need? It is VERY easy to forget about something obscure like the System.Drawing.Obscure namespace.
 
Hi there, and many thanks for your reply!
I did a bit more tinkering, and the mystery is almost solved. I was indeed having a bit of a cant-see-the-wood-for-the-trees experience

Basically there was a rogue typed dataset that decided to stop working, so once i re-created that the project built fine, the dll was created, and they lived happily ever after.

However.

The BL namespace was created as MyCompany.MySolution.BusinessLayer, so obviously i wanted to have the DAL as MyCompany.MySolution.DataAccessLayer. It is mulishly not allowing me to do this!! It works fine for just plain DataAccessLayer, but not as MyCompany.MySolution.DataAccessLayer!!! Why?!?!

I tried this about three times last night, and no joy - however i will try once more this morning to ensure i wasnt missing something obvious (as is too often the case)

thanks again!
 
I think you might be having some problems with inheritance and/or Visual Studio. Of course, the filenames have absolutely nothing to do with how the namespaces are actually organized. It's just logical to make the filenames mirror the organization. You could have System.dll built on top of System.Data.OleDb, but that would be confusing and stupid (yet microsoft still didn't do it).

From what I read, it seems that the business layer is being built on top of the data access layer. Hence your naming schema should be something like:

MyCompany.MySolution.DataAccessLayer
MyCompany.MySolution.DataAccessLayer.BusinessLayer

Possibly (?), Visual Studio is trying to enforce a logical naming schema and therefore won't let you name your files the way you want!

So what do I mean about all this "built on top of" business? Let's look at the asp.net web controls since I'm familiar with them.

Every web control has some similar properties/methods like backcolor, forecolor, enabled etc. It would be redundant and a drag to implement ALL of those properties/methods on EVERY web control. Instead, Microsoft created a class called WebControl. It would look something like this:

namespace System.Web.UI.WebControls
{
public abstract class WebControl
{
public sometype BackColor
{
//get/set logic in here
}
public bool Enabled
{
//get/set logic in here
}
private MicrosoftOnlyFunction()
{
//handles day to day plumbing
}
}

public class TextBox : WebControl
{
public string Text
{
//get/set logic in here
}
}
}

What's going on there is TextBox inherits all the programming of WebControl. Logically, WebControl must be upstream of TextBox. Having WebControl potentially inherit from TextBox would be terrible! The universe could end. In this case, WebControl is in the same namespace as TextBox. That's not the case with Control:

System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.TextBox

WebControl : Control
TextBox : WebControl

So you see that Control must be upstream of WebControl which must in turn be with/upstream of TextBox. Sooooo if your BL uses anything in your DAL, then DAL must be upstream of BL. You can tell if this needs to be because there will be a

using DataAccessLayer;

in your BL namespace.

Anyway, I hope that's your problem because that was a lot of typing!

LATE
 
Hey there - finally managed to get back to this.

thanks a bunch, that's exactly what it was. i didnt put two and two together about the fact that if BL needs to have a reference to DAL, i should have
MyCompany.MySolution.DataAccessLayer
MyCompany.MySolution.DataAccessLayer.BusinessLayer
and finally
MyCompany.MySolution.DataAccessLayer.BusinessLayer.WebLayer
for the web layer to have a reference to the BL.

that's smashing - it's all become clear (well, clearer!). Amazing what one can miss when reading a book chapter on inheritance, it's like a different story when you get to the "practical" side!

Thanks loads for taking the time, very much appreciated!

btw - is "LATE" an acronym, a name, or merely an observation of the time of day?
 
If you must know about LATE...

Very few people take good pictures. I happen to be one of the masses. When my friends and I received our yearbooks last year, we naturally found each others pictures as grounds for ridicule. I looked like a Colombian drug lord in my picture. Now usually I'm more of the type to say "Good bye" or "See you later." However, once I saw that picture, I had to act like a gang member, so I started saying LATE! as low as I could. Everyone hates me for it, so I keep on of course until I don't even notice if I'm signing off LATE on a forum or with a client...

So there's the autobiography. LATE.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top