The type or namespace name 'DirectoryServices' does not exist in the namespace?

Ali picture Ali · May 21, 2012 · Viewed 63.5k times · Source

CS0234: The type or namespace name 'DirectoryServices' does not exist in the namespace 'System' (are you missing an assembly reference?)

This page was working fine,show records from directly services with no error. but now it gives the above error.

 <asp:GridView ID="gvUsers" runat="server" AutoGenerateColumns="false" DataSourceID="odsUsers"
                                    AllowPaging="true" AllowSorting="true" Width="100%">
<Columns>
 <asp:TemplateField HeaderText="User Name">
 <ItemTemplate>

<%#((System.DirectoryServices.DirectoryEntry)Container.DataItem).Properties["userPrincipalName"].Value%>

   </ItemTemplate>
   </asp:TemplateField>
/Columns>
</asp:GridView>

Project builds successfully but when I open the page then it gives error

Answer

Kevin picture Kevin · Aug 7, 2012

After you add your directory services reference, right click on the reference and go to properties. Set "CopyLocal" to true.