1

I have a solution composed by 3 projects.

  • one for Entity framework that contains my edmx diagram
  • one for my core business
  • and one for my web app

When I publish my code on a server or hosting service I get this runtime error:

{"Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.":"EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"}

I get this error because my entity framework assemblies is not published. The entity framework dll file is missing on my server. I know why. I didn't referenced it in my web app project because this assemblies is not required in this project. The assembly is referenced in my two other projects.

I can easily fix my issue by adding the entity framework reference in my web app. Can I do that? yes but is it good programming to add a reference to an assembly that is not directly used by the project? What can I do?


More information

  • one for Entity framework: reference Entity Framework
  • one for my core business: reference Entity Framework because I manipulate my entities here
  • and one for my web app: web site that act like facade between the UI and the core business. I don't reference or use Entity Framework here.

I don't have any compilation error> I only have a runtime error because my entity framework is not published.

In Windows Application in this case I don't reference my dll in the project but I copy it with a post build action. I don't know what to do in the case of a web app I need to publish or deploy.

EOF
  • 6,273
  • 2
  • 26
  • 50
Bastien Vandamme
  • 17,659
  • 30
  • 118
  • 200
  • Which project(s) give you that error? – gunr2171 Sep 15 '14 at 15:52
  • 2
    If A uses B, and B uses C, then A have to reference C in addition to B. Compiler is usually more consistent when checking for dependencies, than any of our feeble attempts. If it says that it needs `EntityFramework`, than it usually really needs it. Recheck once more that you do not use anything EF-related. – Eugene Podskal Sep 15 '14 at 15:52
  • if it's in the app.config or web.config and you are not using the EntityFramework dll then just remove it.. if it's missing from the server then you need to install .net 4.0 or 4.5 to that server – MethodMan Sep 15 '14 at 15:53
  • Good practice would be to split your libraries, so that you link only the functionality you really need. – Vojtěch Dohnal Sep 15 '14 at 15:55
  • Kinda bizarre to do it this way. Just remove EF from the references. Now the compiler tells you what you overlooked. – Hans Passant Sep 15 '14 at 17:59

1 Answers1

0

Your problem is as far as I understand that assemblies referenced indirectly do not get copied to the output directory. So I believe the best way is to add a reference to EntityFramework also to both your web and windows projects.

Check this answer: Copying indirectly referenced assembly to output directory - assembly is missing

References are not automatically cascaded, so adding a reference to OLAF.Tools does not also add a reference to SQLXML. If you want to deploy SQLXML with your exe, then the most convenient way to do that is to explicitly add a reference to SQLXML from your exe, and set it to copy local. Without this, it is not deployed.

Community
  • 1
  • 1
Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105