0

I have 2 projects: X and Y. Project X is a class lib that references, lets say, EF 6. Project Y as a console app that references X. Why do i get a cannot load dependency exception if i do not add, lets say, EF 6 to project Y? Is there a way to "carry" those references to project Y?

The idea here is that Y should not know about EF-6, not to say its dependencies!

Leonardo
  • 10,737
  • 10
  • 62
  • 155
  • 1
    @leonardo, if you want to use project Y, without referencing `EF-6`, which is an ideal requirement, you should not access any direct or inherited instances of `EF-6` classes i.e. DataContext, ExceptionClasses. The best way to go about it is to make a wrapper over your EF functions in the X project and never use the context directly in the Y – Manish Mishra Dec 30 '13 at 13:55
  • @ManishMishra i know! and i did that! in fact, right now, my code does nothing at all! its empty! theres absolutally nothing there! just a empty Main! – Leonardo Dec 30 '13 at 14:02

1 Answers1

2

You are very probably exposing classes to Y that inherit from Entity Framework, most probably your Entities, your Context if project Y uses that, etc.

Therefore, project Y needs to reference Entity Framework, because it cannot otherwise resolve the classes (base properties, logic) that your classes inherit from.

The only way to hide Entity Framework from Y is to make it completely independent of it. So for instance you may create a service class in project X that project Y calls, and this class' methods does not expose any classes from Entity Framework, nor any classes that inherit from classes in Entity Framework. You can do that by creating your own entities that you then map to from queries in Entity Framework etc.

Another way is to hide project X behind a webservice (WCF). Then project Y calls the webservice, which calls the logic in project X. The WCF webservice exposes nothing from Entity Framework, so your project Y does not need any references to it.

Roy Dictus
  • 32,551
  • 8
  • 60
  • 76
  • right now my code is empty! theres just a empty main function! And if that was the case, i would get a compile-time error, not a runtime one... – Leonardo Dec 30 '13 at 14:03
  • 1
    I don't think you understand my answer. You mean your Y project is empty, but your X project, that Y references, exposes classes that inherit from Entity Framework classes. So regardless of whether Y already contains logic, the fact that it references X, which exposes classes that inherit from EF, means that Y must also reference EF. – Roy Dictus Dec 30 '13 at 14:07
  • That does not make much sense Roy, you see, basically what ur saying is that my interface & controllers are bound to my OR/M solution, when only my "repository solution" should. Right now the whole X project has only 1 class and that class has 1 method (no properties) that returns null and take no parameters! X is basically a empty project that has EF installed on it via Nuget... still i cant get it to run without adding EF to the console app project... im sorry if i sound frustrated... – Leonardo Dec 30 '13 at 20:19