views:

226

answers:

3

I am trying to share a common namespace between two projects in a single solution. The projects are "Blueprint" and "Repositories". Blueprint contains Interfaces for the entire application and serves as a reference for the application structure.

In the Blueprint project, I have an interface with the following declaration:

namespace Application.Repositories{
    public interface IRepository{
        IEntity Get(Guid id);
    }
}

In the Repositories project I have a class the following class:

namespace Application.Repositories{
    public class STDRepository: IRepository
    {
        STD Get(Guid id){
             return new SkankyExGirlfriendDataContext()
                           .FirstOrDefault<STD>(x=>x.DiseaseId == id);
        }
    }
}

However, this does not work. The Repositories project has a reference to the Blueprint project. I receive a VS error: "The type or namespace name 'IRepository' could not be found (are you missing a using directive or an assembly reference?) - Normally, this is easy to fix but adding a using statement doesn't make sense since they have the same namespace. I tried it anyway and it didn't work. The reference has been added, and without the line of code referencing that interface, both projects compile successfully. I am lost here. I have searched all over and have found nothing, so I am assuming that there is something fundamentally wrong with what I'm doing ... but I don't know what it is. So, I would appreciate some explanation or guidance as to how to fix this problem. I hope you guys can help.

Note: The reason I want to do it this way and keep the interfaces under the same namespace is because I want a solid project to keep all the interfaces in, in order to have a reference for the full architecture of the application. I have considered work arounds, such as putting all of the interfaces in the Blueprint.Application namespace instead of the application namespace. However, that would require me to write the using statement on virtually every page in the application...and my fingers get tired. Thanks again guys...

+1  A: 

This is possible.

For example, mscorlib.dll and System.dll are two different C# projects that both define classes in the System namespace. (among others)

This error would happen if the Repositories project doesn't reference Blueprint.

SLaks
As stated, the Repositories project DOES reference Blueprint. The error still occurs.
smartcaveman
Are you sure? Do the classes in Blueprint show in IntelliSense? Try removing the reference and re-adding it (from the Projects tab)
SLaks
A: 

For what you are trying to archieve, you can also try to put everything into one assembly and declare all classes as internal instead of public. This way the program that uses it will only see the interfaces. You will have to create a set of factory classes that create instances of specific interfaces depending on some parameters. This is really the way to go, because the small assemblies cause a lot of overhead. See the Microsoft Performance Guidelines.

Jouke van der Maas
I took out the AssemblyInfo.cs and added a link in each project to a single assembly file, so I am expecting that they will compile as one assembly. Is this not accurate?
smartcaveman
+1  A: 

Alright - So, I marked SLaks as right because his answer was correct and will probably be the solution for any one else viewing this in the future. My problem had to do with the other 6 project files in my solution. I unloaded them and rebuilt the solution with only the two posted instances and suddenly my Intellisense started working. Even though these two projects had no errors, the errors in other projects were causing some problem in the compile. Damn... Thanks guys.

smartcaveman