The module 'System.Data.Linq' Version = 4.0.0.0, Culture = neutral, Publickeytoken = b77a5c561934e089 'must be specified

I have a Visual Studio 2012 web application (fw. 4.5) where I am trying to execute linq in my sql database. I 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 express database.

I am trying to access data using linq 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 completed in my project and I added manually

  <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 the runtime section of web.config. However, the error still exists.

Another problem is that when I put the DataContext file in the App_Code folder, I get another error.

Intellisense reports: Cannot resolve select symbol

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

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

Cannot resolve the "Linq" character.

This web project is based on the standard "ASP.NET Web Form Application" and I'm trying to abandon the basic programming, so I don’t see what I'm doing wrong here.

+6
source share
3 answers

This error usually occurs due to a mismatch in the version of the DLL. Try deleting the bin folder and reinstalling the application.

+4
source

I believe that this means that you are referring to classes / methods that are defined in another DLL (assembly). Your project should have a link to this library (DLL / assembly) so that it can compile your project. (has nothing to do with the web application configuration file)

Within the project, right-click the heading for the Links section and select Add Link. Go to the place of assembly (it should be in the section "Assemblies-> Frames-> System.Data.Linq)

Greetings

+3
source

It also seems that you can add “Linq to SQL classes” to the “APP_Code” folder. I could not query the datacontext when it was saved in the APP_Code folder.

+2
source

Source: https://habr.com/ru/post/951533/


All Articles