Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module 'System.Data.Linq' Version=4.0.0.0, Culture=neutral, Publickeytoken=b77a5c561934e089' should be referenced

I have a Visual Studio 2012 web application (fw. 4.5) where I try to linq to my sql database. I've added a datacontext to my project and put it in the root folder. In the datacontext file I added a table named GlobalMenu from my SQL 2012 expressdatabase.

I'm trying to access the data with linq by using the following command:

DataContextDataContext db = new DataContextDataContext();
var menupages = from p in db.GlobalMenus
                select p;

Intellisense reports:

Module 'System.Data.Linq' Version=4.0.0.0, Culture=neutral, Publickeytoken=b77a5c561934e089' should be referenced

When I compile and try to run my application I get:

CS0012: The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

System.Data.Linq 4.0.0.0 is refenced in my project and I've manually added

 <dependentAssembly>
    <assemblyIdentity name="System.Data.Linq" publicKeyToken="b77a5c561934e089"/>
    <bindingRedirect oldVersion="1.0.0.0-4.5.0.0" newVersion="4.0.0.0"/>
  </dependentAssembly>

in runtime section in web.config. However the error is still there.

Another problem is when I put my DataContext file into App_Code folder I get another error.

Intellisense reports: Cannot resolve symbol 'Select'

After compiling and running the web application I get a runtime error inside the datacontext file in the designer file.

using System.Data.Linq;
using System.Data.Linq.Mapping;

Cannot resolve symbol 'Linq'.

This web project is based on a standard "ASP.NET Web Forms Application" and what I'm trying to do is quit basic programming, so I can't see what I'm doing wrong here.

like image 656
jona Avatar asked Aug 12 '13 06:08

jona


1 Answers

This error is commonly because of a DLL version mismatch. Try deleting your bin folder and rebuilding the application.

like image 114
Thamotharan Karuppiah Avatar answered Sep 19 '22 22:09

Thamotharan Karuppiah