Reputation: 3625
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
Upvotes: 22
Views: 75626
Reputation: 227
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
Upvotes: 14
Reputation: 1411
It will work if assembly "System.DirectoryServices.AccountManagement" is added in the references. Adding System.DirectoryServices will not work.
Upvotes: 0
Reputation: 2379
The easy way that worked for me was to right-click on References => Add Reference, and select System.DirectoryServices (and needed subassemblies).
Upvotes: 3
Reputation: 2792
I ran into this issue in Visual Studio 2015 with an MVC project that was targeted for .NET Framework 4.5.2. Changing the target framework to .NET 4.5 resolved the problem.
Upvotes: 2
Reputation: 3181
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>
Upvotes: 20
Reputation: 1
I had the same problem. I did a search for DirectoryServices.dll in my windows folder. Since all the versions that came up had the same size, I picked one and copied it to the bin folder in my website. If you don't have a bin folder, just create it. Once I did that, I was able to open my webpage without errors.
Upvotes: 0
Reputation: 431
After you add your directory services reference, right click on the reference
and go to properties
. Set "CopyLocal"
to true.
Upvotes: 43
Reputation: 855
You need to add an import directive on your asp.net page. Make sure it is fully qualified. Make sure you have a reference to the assembly in your project as well.
<%@ Assembly Name="System.DirectoryServices, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" %>
Upvotes: 1
Reputation: 30656
Looks like you need to add a reference (in your project) to System.DirectoryServices
. Since you're using it in what looks like an aspx markup page, sometimes the compiler will let those fly during "build" but fail when you actually execute the page.
Upvotes: 0