views:

435

answers:

1

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.

A: 

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.

Bryan
I suspect you are right. I removed the project and started from Scratch, and now it is working without the App_Code directory. I'm not entirely sure what I did different this time though.
Gerald Schneider