Gerald Schneider
Gerald Schneider

Reputation: 17797

Assembly reference from ASP.NET App_Code directory

I have trouble getting a custom ObjectDataSource for an asp:ListView control to work. I have the class for the DataSource in the App_Code directory of the web application (as required by the asp:ListView control).

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Web;
using System.DirectoryServices;

    [DataObject]
    public class UsersDAL
    {
        [DataObjectMethod(DataObjectMethodType.Select)]
        public List<User> LoadAll(int startIndex, int maxRows, string sortedBy)
        {
            List<User> users = new List<User>();

            DirectoryEntry entry;

            return users;
        }
    }

As soon as I add using System.DirectoryServices; the page crashes with this message:
Compiler Error Message: CS0234: The type or namespace name 'DirectoryServices' does not exist in the namespace 'System' (are you missing an assembly reference?)
Without the usage of System.DirectoryServices the page loads without problems.

The reference is there, it is working in classes outside the App_Code directory.

Upvotes: 1

Views: 6494

Answers (1)

Bryan
Bryan

Reputation: 8788

I suspect a mix-up between Web Application Project and a Web Site. Which do you have?

Do you have a reference to System.DirectoryServices in your web.config? Probably not. And this is why it's not working.

If you have a Web Application Project, dispense with App_Code. It is unnecessary, and potentially harmful. Case in point, your trouble here.

Upvotes: 3

Related Questions