English 中文(简体)
命名空间中不存在类型或名称空间名称目录服务吗?
原标题: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?)

此页面工作正常, 显示直接服务的记录, 没有任何错误, 但现在它给出了上述错误 。

 <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>

工程成功构建工程, 但当我打开页面时, 它会出错

问题回答

在添加目录服务参考后,右键单击 reference 并转到 property 。设置 为真。

我非常肯定,我完全错误地将我的应用程序从我的开发盒子“公布”到我的IIS盒子。然而,我发现这个解决方案这里,它为我工作。

如果您正在使用 Web 应用程序, 请在 Web. config 中添加以下代码 。

<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:方案文件 参考集合 微软框架。 NETFrameworkv4.6.1”

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

5 - Select them
6 - Press "OK" Button

对我而言,最容易的方法就是右键点击 参考 {gt; 添加引用, 并选择系统。 服务局( 以及需要的子集) 。

我在2015年视觉工作室与一个MVC项目一起遇到了这个问题,该项目针对的是.NET框架4.5.2。 将目标框架改为.NET4.5, 解决了这个问题。

您需要在 asp. net 页面上添加导入指令。 请确定它完全合格 。 请确定您在您的工程中也提及组件 。

 <%@ Assembly Name="System.DirectoryServices, Version=2.0.0.0,
     Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" %>

您似乎需要添加一个引用( 在您的工程中) 到 < a href=" http://msdn. microsoft. com/ en- us/library/ system. directoryservices. aspx" rel = "nofollow"\\ code > System. DistroyServices 。 由于您在看起来像一个 aspx 标记页面上使用它, 有时编译者会在“ 建设” 期间让这些文件飞过, 但当您实际执行该页面时失败 。

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.

如果在参考文献中添加“ 系统、 服务器、 会计管理” 组装, 将会有效 。 添加系统 。 服务器将无效 。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签