1

I have a c# project, where the default namespace is Project.App - I have another project, where the default namespace is Project.Service.

I'm including the DLL created from Project.Service as a reference in Project.App - The reason being the projects are in two different solutions, maintained by two different groups.

When I try to use the reference in code and compile, I'm always getting an error that says "The type or namespace 'Service' does not exist in the namespace 'Project'".

What am I missing here?

Edit: I found the solution to my issue: Namespace not recognized (even though it is there)

Community
  • 1
  • 1
M.R.
  • 4,737
  • 3
  • 37
  • 81
  • [What have you tried?](http://whathaveyoutried.com) – GameScripting Jan 03 '13 at 18:45
  • How are you adding the reference? What does the code look like? – David Jan 03 '13 at 18:46
  • Does the error occur on a "using" statement within Project.App? – Brendan Hannemann Jan 03 '13 at 18:47
  • @GameScripting: this is very basic - I'm just trying to use a class from a reference - I'm not sure what other way to try. – M.R. Jan 03 '13 at 18:49
  • @David: I just right-clicked in visual studio, and added reference and pointed to the DLL – M.R. Jan 03 '13 at 18:49
  • @unicron: Its fine when I add that statement. But when compiling, thats where the error is... – M.R. Jan 03 '13 at 18:50
  • Right-click the reference and check the `Properties` to see if anything is odd - specifically the Aliases (`global`), Copy Local (`True`), and Specific Version (`False`). – D Stanley Jan 03 '13 at 19:01
  • When adding the reference, I see you are not using a Project Reference (local to the solution), and just adding the compiled .dll of the other project. Have you tried combining them into one solution? Also, try opening the referenced .dll in Class Explorer and see if it has the correct namespace. – Brendan Hannemann Jan 03 '13 at 19:01
  • I could have it as part of the solution, but its being maintained somewhere else...so I don't have access to the source code.. – M.R. Jan 03 '13 at 19:07

6 Answers6

1

How to: Use the Namespace Alias Qualifier (C# Programming Guide)

//example
using colAlias = System.Collections;
rick schott
  • 21,012
  • 5
  • 52
  • 81
  • Tried that - in my case, it still says the same thing. After compiling, what it says is that "Service" doesn't exist. Its like when you say Project.[something] it is only going to the local project (which is name Project.App) – M.R. Jan 03 '13 at 18:51
0

I would check first if the reference it is really being added: maybe the target framework in the Service dll is different (later version) than the one in your app.

Hugo
  • 6,244
  • 8
  • 37
  • 43
0

I read an article a while back (after stylecop told me to move my using statements) that moving using statements inside the current namespace can help with namespace clashes like this.

namespace example
{ 
   using xxxxx
}

See the following post: Should 'using' statements be inside or outside the namespace?

Community
  • 1
  • 1
Steve's a D
  • 3,801
  • 10
  • 39
  • 60
0

Try giving the Project.Service dll an alias and then importing the alias into your code. Like this:

  1. Right-click on the referenced dll in your project's References folder and click 'Properties'
  2. In the Aliases field enter a new alias for this reference, something like 'Services'
  3. On your code page add this directive at the top of the page: extern alias Services;
  4. Add a using statement like this: using Service = Services;
  5. Reference the Project.Service namespace like so: Service.DoSomthing();

You should be good to go at this point.

Shai Cohen
  • 6,074
  • 4
  • 31
  • 54
0

Since you seem to have reference correctly...

All classes in Project.Service could be internal so other projects will not "see" anything.

If it is true - make public OR make your assembly friend of other assembly "InternalsVisibleTo" (note that it requires both to be strongly signed).

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
0

Have you verified that the class you want to use is in the Project.Service namespace and that it is public? Even if Project.Service is the default namespace, that doesn't guarantee that any classes in the assembly have that namespace.

JLRishe
  • 99,490
  • 19
  • 131
  • 169