Problem
Error navigating to a specific page (in local debugging): CS0012: The type "System.Data.Linq.DataContext" is defined in an assembly that is not referenced. You must add a reference to the assembly "System.Data.Linq, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089".
The following are the lines of code in the error message:
Line 28:
Line 29:
Line 30: public class _Page_Views_blah_granny_cshtml: System.Web.Mvc.WebViewPage {
Line 31:
Line 32: hidden line
All other pages work fine - this only happens when accessing one page in particular. The link works on all other pages. As far as I can tell, this is not a link issue.
I spent a lot of time studying this problem.
All the answers that I found suggest switching to web.config and putting a link to the linq assembly in the system.web> configuration> assembly file. My mine has no assemblies, and I suspect this is more for older versions. I did it anyway. This gave me another mistake saying that she does not know what to do with assemblies.
I uninstalled system.data.linq and added it again.
I rebooted VS and my computer.
My code - as VS is generated by default - has System.Linq.
Background is how it started:
The app is MVC 4, C #.
I created a new class in my DataContext, added a new controller, and created a strongly typed view.
Here is a very similar code (most likely not needed, but just in case).
Two classes:
public class granny { public string data { get; set; } public string criteria { get; set; } } public List<granny> getGranny() { var a = from x in grannytable join dx in anothertable on x.criteria equals dx.criteria select new granny { data = x.somenewdata; }; return a.ToList(); }
Here is the controller:
public ActionResult granny() { return View(db.getGranny()); }
Nothing special.
A page is a typical razor view, a strongly typed "List" ... it has a table that iterates over, dumping data as it appears.
I am happy to provide any additional code as needed.
I did not bother with web.config. I did not delete or correct any of the links on the pages. All other looks work wonderfully.
When I run it locally and try to go to / granny, I get the above error.
Thanks for your help!
SOLUTION I went to the links for System.Linq too (or for older versions, say System.Data.Linq) and changed CopyLocal to True.