在 XP 上使用 C# 和目录服务崩溃 [英] Crashing with C# and Directory Services on XP

查看:28
本文介绍了在 XP 上使用 C# 和目录服务崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 C# 和目录服务进行一些简单的数据检索,但由于某种原因,它在任何 XP 计算机上都不起作用.如果我在 Server 2003 机器上运行我的代码,则没有问题.我花了相当多的时间试图找出 XP 上是否有我需要的可再发行组件,或者该功能是否根本不存在,但我找到了对在 XP 下使用类似代码的其他开发人员的引用.如果有人有任何经验或建议可以分享,我将不胜感激.

I'm trying to do some simple data retrieval with C# and Directory Services, but for some reason it doesn't work on any XP machines. If I run my code on a Server 2003 machine, there are no problems. I've spent a fair bit of time trying to find out if maybe there's some redistributable I need on XP or if the functionality simply isn't there, but I've found references to other developers who have similar code working under XP. If anyone has any experience or advice to share, I'd appreciate it.

一个让我崩溃的简单代码片段:

A simple code snippet that's crashing for me:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.DirectoryServices;

namespace IIS_Site_Query_Tool
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            DirectoryEntry W3SVC = new DirectoryEntry("IIS://localhost/w3svc");
            foreach (DirectoryEntry Site in W3SVC.Children)
            {
                //Do some data processing
            }
        }
    }
}

在 XP 下运行此程序会出现以下错误,HRESULT 为 -2147463168:

Running this under XP gives me the folowing error with an HRESULT of -2147463168:

System.Runtime.InteropServices.COMException was unhandled
  Message="Unknown error (0x80005000)"
  Source="System.DirectoryServices"
  ErrorCode=-2147463168
  StackTrace:
       at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
       at System.DirectoryServices.DirectoryEntry.Bind()
       at System.DirectoryServices.DirectoryEntry.get_IsContainer()
       at System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(DirectoryEntry container)
       at System.DirectoryServices.DirectoryEntries.GetEnumerator()
       ...

谷歌搜索错误中的各种信息使我认为这是一个非常通用的 COM 互操作错误,此时我没有想法.任何帮助表示赞赏!

Googling the various pieces of information in the error lead me to think that it's a pretty generic COM interop error, and I'm out of ideas at this point. Any help is appreciated!

推荐答案

基于堆栈跟踪和反射器,它看起来像是对 ADsOpenObject 正在返回 E_ADS_BAD_PATHNAME.此错误表明您提供给 DirectoryEntry 类的路径在当前计算机上无效.

Based on the stack trace and reflector it looks like a call to ADsOpenObject is returning E_ADS_BAD_PATHNAME. This error indicates that the path you supplied to the DirectoryEntry class is not valid on the current machine.

如果安装了 IIS,则可能是您的计算机上没有正确安装 IIS 提供程序.

If IIS is installed, then it's possible that the IIS provider is not properly installed on your machine.

有关更多详细信息,请参阅此 SO 问题:ADSI 不会从 XP 工作站连接到 IIS

See this SO question for more details: ADSI will not connect to IIS from XP Workstation

这篇关于在 XP 上使用 C# 和目录服务崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆