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?
A couple of places to start:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With