Namespace issue

R

Robert Warnestam

I've two class libraries, where one is referencing the other.

The first library looks like this; (assembly name and root name space is set to Codab.Parser)
namespace Codab.Parser
{
public class Parser
{...}
...
}
The second library looks like this (assemble name and root name space is set to Codab.TapNet)
using Codab.Parser;
namespace Codab.TapNet
{
public class FileExport
{
private Parser = fParser;
}
...
}
My problem is that I can't access the Parser class directly (I receive the message 'Codab.Parser' is a 'namespace' but is used like a 'type') in the second library. I really don't want to use full names when accessing this class or something else in this library.
If I change the namespace to something like "Codabxx" it works!

Can somebody please explain what is going wrong.

Thanks

Robert Warnestam
 
D

Dan Bass

1. The name of the namespace and the name of the class are the same
(Parser).
2. There's no variable name... you don't declare "private int = 3", but
"private int myCounter = 3"

When you're referencing Parser in your declaration, the compiler is
referencing Codab.Parser, not Codab.Parser.Parser...

To fix this, you could remove the "using Codab.Parser" and then in the
variable declaration put
private Codab.Parser.Parser myParser = fParser;

HTH

Dan.

---------------------------------------------------------------



I've two class libraries, where one is referencing the other.

The first library looks like this; (assembly name and root name space is set
to Codab.Parser)
namespace Codab.Parser
{
public class Parser
{...}
...
}
The second library looks like this (assemble name and root name space is set
to Codab.TapNet)
using Codab.Parser;
namespace Codab.TapNet
{
public class FileExport
{
private Parser = fParser;
}
...
}
My problem is that I can't access the Parser class directly (I receive the
message 'Codab.Parser' is a 'namespace' but is used like a 'type') in the
second library. I really don't want to use full names when accessing this
class or something else in this library.
If I change the namespace to something like "Codabxx" it works!

Can somebody please explain what is going wrong.

Thanks

Robert Warnestam
 
?

=?ISO-8859-2?Q?Marcin_Grz=EAbski?=

Hi,

In addition to Dan's answer, i can recommend you to use name
of namespaces different than name of its classes.
Elswere you've got to write full class name (every time)
to make that class visible in VS (or c# compiler)...
But i think that its boring so much :-(

HTH
Marcin
 
R

Robert Warnestam

Thanx for the reply

1) Yes they are the same.
2) Typing error, of course it should be "private Parser fParser;" instead

I know I can use fullnames, but that is not what I want.

/Robert
 
R

Robert Warnestam

Thanx for your reply.

Yes it's boring too write the fullname!!!

I tried to change the namespace of the second assembly, this was the result;

Changing the namespace to "Codab.Somethingelse" does not work
Changing the namespace to "BlaBla.TapNet"

And of course I can't accept to change the root of the namespace to
something different than our company. The strange thing is that I have a
similar situation in another part of my solution - and it works!!! I'm using
VS2005 - could it be a bug?

/Robert
 
D

Dan Bass

Robert,

In that case you should insure the namespace and class name are different.

Thanks.

Dan.
 
G

Guest

Try:

using CodabParser=Codab.Parser.Parser;
....
private CodabParser fParser=new CodabParser(...);

But I agree that fixing up your namespace/classname issue would probably be
a better solution in the long run.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top