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
After you add your directory services reference, right click on the reference
and go to properties
. Set "CopyLocal"
to true.
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>
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
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