Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CS0012: The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced

Helllo, I get this error:

CS0246: The type or namespace name 'DataClasses1DataContext' could not be found (are you missing a using directive or an assembly reference?)

For this .aspx file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WebApplication1_admin_Places : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataClasses1DataContext db = new DataClasses1DataContext();
        var query = (from m in db.Places orderby m.Name select m);
        PlacesList.DataSource = query;
        PlacesList.DataBind();
    }
}

The thing is, on / folder I can access DB, but on /admin folder i get this error.

What am I doing wrong?

EDIT

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=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

What does that mean?

like image 465
natiz Avatar asked Nov 28 '10 22:11

natiz


2 Answers

A couple of places to start:

  • Where is the dll that contains DataClasses1DataContext? Is there a reason that you can get to it from one folder and not the other
  • Is there a config file in the admin folder that is overriding values set in the root config file?

Edit

It looks like this is a configuration problem. The config probably says that the msl (model) file is in the current directory, it is in the root directory. Therefore it works when you are on the root but not when you are in admin.

see: MetadataException when using Entity Framework Entity Connection for a similar problem.

like image 191
Shiraz Bhaiji Avatar answered Oct 05 '22 14:10

Shiraz Bhaiji


This error can occur when an attempt to load an assembly is caused by the .ASPX markup, even if the assembly is already referenced by the project! The project-wide solution mentioned in passing here is to add the assembly to the list of assemblies in the web.config assemblies Element for compilation, eg.

<compilation>
 <assemblies>
  <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  ...

The alternative on a per-page basis is the @ Assembly page attribute, but this has to be added to every page causing the ASP.NET runtime to attempt to load the missing assembly type.

like image 30
user423430 Avatar answered Oct 05 '22 12:10

user423430