0

I have a few differenet namespaces in my solution and I want to use an object called "Doctor" from namespece BL_Backend inside another namespace called DAL. I've tried adding a Refference to DAL (a refference for BL_Backend), and then adding "using BL_Backend;" but it wouldn't work. still classes such as Doctor won't appear as known ones inside namespace DAL.

namespace BL_Backend
{
…
namespace DAL
{
    …
    //Here create object as "Doctor" for BL_Backend class
}
}

For example, when i call a constructor of a doctor from DAL it says this constructor does not exists but when i write the exact same command at namespace bl_backend it works fine.

thanks alot!

2
  • It sounds like you're using the word namespace when in fact you're probably referring to assemblys. Assemblies and namespaces are two separate concepts in .NET. A single assembly (something you can reference) may contain multiple types in multiple namespaces. And the types within a single namespace may come from multiple assemblies. That's why, in all the MSDN documentation for framework types, you'll find both the namespace and the assembly listed. Commented Mar 18, 2014 at 7:09
  • This is very wrong practice to use namespace within another namespace.. you should instead use namespace1.namespace2 if you want to have a standard order of namespaces within your solution. Commented Mar 18, 2014 at 7:21

3 Answers 3

1

I assume Doctor is declared as internal class in BL_Backend assembly. Note - if class does not have public access modifier, then by default it will be internal:

namespace BL_Backend
{
    class Doctor // this class is internal
    {

    }
}

Internal classes are visible only within assembly they are defined (well, there is attribute InternalsVisibleTo which allows other assemblies to see internal classes, but without applying this attribute, class is not visible to other assemblies).

Sign up to request clarification or add additional context in comments.

1 Comment

didn't know classes need to be public also, thanks alot - it works !
0

If you want to use a class Doctor from an assembly BL_Backend in a DAL you must add a reference in DAL to the BL_Backend not vise versa.

Comments

0

Classes without a modifier are internal by default, so ensure that your modifier is public. As a second option pay attention to the build order - its not a problem in VS12+ anymore, but in further versions it was.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.