Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 660
Ali Avatar asked May 21 '12 18:05

Ali


3 Answers

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

like image 58
Kevin Avatar answered Sep 21 '22 09:09

Kevin


I'm pretty sure that I'm "publishing" my application from my development box to my IIS box completely incorrectly. However, I found this solution here, and it worked for me.

If you are using web application then in your web.config add the following code.

<compilation debug="true" targetFramework="4.0" >
    <assemblies>
        <add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.DirectoryServices.AccountManagement, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    </assemblies>
</compilation>
like image 30
Slogmeister Extraordinaire Avatar answered Sep 19 '22 09:09

Slogmeister Extraordinaire


1 - Right-Click Mouse Button on "References"
2 - Click "Add Reference ..."
3 - Click "Browse" Button
4 - Find the following files in folder:

"C:\Program Files\Reference\Assemblies\Microsoft\Framework\.NETFramework\v4.6.1"

-System.DirectoryServices.dll
-System.DirectoryServices.AccountManagement.dll

5 - Select them
6 - Press "OK" Button

like image 30
Ali Reza Avatar answered Sep 20 '22 09:09

Ali Reza