I have a Visual Studio 2012 solution that consists of both a web application and some client-side code. The way the application is structured, there is a shared class library used for data access.
The client-side code needs to target .NET 4, since I’ll be deploying that to machines that may not have .NET 4.5. Since I control the web server end, I can assume .NET 4.5 for that.
Now, the data-access library needs to be used by both the client and server end, and so it needs to use only .NET 4. However, this is causing me unexpected problems.
The data-access library uses Entity Framework. Being .NET 4, it uses EF version 4.4. However, the web application also needs to reference the Entity Framework, and being .NET 4.5 it uses EF version 5.0.
This results in an (intermittent) error when I try to run the application. (I’m starting both the website and the client code from VS2012, on the same machine).
The website works OK if I just enter a URL into the address bar on the browser – its able to use the data-access library to fetch data without problems. However, when I use the client application, it (usually, not always!) gets a server error back from the web end saying that it (the web end) can’t load the Entity Framework assembly:
Could not load file or assembly ‘EntityFramework, Version=5.0.0.0, …
The located assembly’s manifest definition does not match the assembly reference.
I’m not sure whether this is only a problem because I’m running in the debugger, on the same machine, or whether this is something that’s going to affect my application once deployed.
Am I doing something crazy here, or should this work OK?
For anyone attempting this: it does work so long as you do a “build solution” prior to hitting “run” (which in my case starts the client-side application in debug mode, but starts the web app without debugging). To debug the web app too, I need to explicitly start that (right-click, debug), and then start the client-side app (right-click, debug). Again, a “build solution” is required every time (and occasionally a “rebuild”).
EDIT: aaaannnndd… suddenly it stopped working. However, I figured out that when I run the client-side application within VS, it builds/updates the EF DLL in the web project bin directory with the one used by the client app, which causes the version-mismatch as soon as the website is accessed, because the website is expecting the later version. To resolve this, I now have a batch file that copies in the correct version of the EF DLL into the website bin directory. So, I can start the client application, then execute my batch file, then start the website. A pain, but at least it now works reliably.