Question

COMException when binding a new System.DirectoryServices.DirectoryEntry object to IIS

Asked by: BurntSky

I'm experiencing a rather interesting problem using the DirectoryEntry object.  Here is the code in question:

try
{
      System.DirectoryServices.DirectoryEntry iisRoot = new System.DirectoryServices.DirectoryEntry("IIS://" + serverAddress + "/W3SVC/1/Root");
}
catch(Exception ex)
{
      Console.WriteLine(ex.Message);
}

Although I haven't included the rest of the method's code, it should suffice to say I'm just using this DirectoryEntry object to create a new virtual directory.  The code seems simple enough, and works perfectly fine when the "serverAddress" parameter is "127.0.0.1" or "localhost" or "192.168.1.100" (my network IP address).  However, as soon as I put in "192.168.1.101" (or the address of any other computer, for that matter) the application throws this:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in system.directoryservices.dll
Additional information: The RPC server is unavailable

The odd thing is that the catch block doesn't catch the exception.  VS.NET (in debug mode) just throws me that error and breaks the debug run and won't show me any exception related information (InnerException, StackTrace, etc.).  So, because of that, I can't drill down at all to see what might be causing the problem at a deeper level.

My dev machine is running: Windows XP Professional (with Service Pack 2), IIS 5, Visual Studio .NET 2003.  I'm wondering if it may be an issue with Service Pack 2, but I'm not sure.

Ideas?  Solutions?

Thanks.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-04-26 at 23:08:35ID21403824
Tags

comexception

,

directoryentry

,

rpc

,

server

Topic

C# Programming Language

Participating Experts
3
Points
500
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Rpc binding vector
    In microsoft rpc Rpc_Binding_vector is a data structure, defined in header rpcdce.h. It contains two elements, 1. count showing number of binding handles in binding handle array 2. array of binding handles In include file rpcdce.h the array size has been given as 1. My do...
  2. MTA stacks generating RPC errors after IIS metabase reinst…
    http://www.experts-exchange.com/Networking/Email_Groupware/Exchange_Server/Q_21129348.html That is the link to the question that generaed the metabase reinstall.... Here is situation...Primary FE/BE Exchange 2003 server had full IIS reinstall along with exchange in reinstal...
  3. configure vs.net
    hi we have just received vs.net 2003, but am having problems getting it to work. we have win2k3 web as a server (intranet), and have installed vs.net 2003 on my pc, but each time i try to create a asp.net web project it gives me an error. the error is the default we acces...
  4. Disabling NFS and RPC-Bind?
    OK, I DID THIS COMMAND...to list all servces...I see a number of RPC and NFS services on this list but I want to only disable the ones that pose a security threat in UNIX systems...I already disabled Telnet, Rlogin, and Finger to start with...I also want to disable NFS and RP...
  5. VS.Net 2003 & VS.Net 2005
    Hi Friends, Can we have VS.Net 2003 & VS.Net 2005 both versions on same machine? If we have both versions installed on same machine, can we expect any problems? Please share your practical experiences and ideas on this thread Thanks, Pinna

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: dunglaPosted on 2005-04-26 at 23:21:57ID: 13873474

When you input IP address of another computer, your code will make a RPC call to remote machine (specified by IP, computer name). At remote machine, when your code prepare to executed, that machine will check for authorization of user who execute the code (mean your account in your local machine). If not authorized then the code will thru exeception.

You can try...catch (COMException ex) for more detail. When you create new instance of DirectoryEntry, remember to parse username and password as well

   System.DirectoryServices.DirectoryEntry iisRoot = new System.DirectoryServices.DirectoryEntry("IIS://" + serverAddress + "/W3SVC/1/Root", "username", "password");

 

by: BurntSkyPosted on 2005-04-26 at 23:33:09ID: 13873514

I've tried passing the appropriate username and password when creating the DirectoryEntry instance, however, it acts the exact same way as without it; when executed against my local machine it works fine, against a remote machine, it doesn't work.  Even if I enable DMZ on my router and forward all calls to my machine and then execute the code against my external IP it throws the same error.  Also, I would think that if the problem was invalid user credentials it would throw a different error (something relating to incorrect permissions).

Concerning the try...catch block: it doesn't work.  I've tried numerous ways around it and it's a very, very odd thing.  If I replace my catch block with:

catch(COMException ex) { ... }
or even:
catch { ... }

it skips right over it and throws the error (instead of executing the code in catch block).  I'm guessing it might be a bug related to poor exception handling for unmanaged code.

 

by: UritsukidojiPosted on 2005-04-27 at 02:26:34ID: 13874204

Could the exception be thrown asynchronously (i.o.w. the excpetion isn't directly thrown when the

new System.DirectoryServices.DirectoryEntry("IIS://" + serverAddress + "/W3SVC/1/Root", "username", "password");

is executed?

If you're using a web application, try if you can catch the exception at global scope in global.asax.cs:

protected void Application_Error(Object sender, EventArgs e)
{
  Exception e = Server.GetLastError();
  if (e is COMException){
   ...
  }
}

If it's a Windows.Forms application, see if one ofthese articles can help you:

User Friendly Exception Handling
http://www.codeproject.com/dotnet/ExceptionHandling.asp

Unhandled exception handling:
http://www.codeproject.com/dotnet/unhandledexceptions.asp

.NET Thread & application level exception handling
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/exceptdotnet.asp

Good luck, Wiebe
http://www.netindustry.nl/blog

 

by: dunglaPosted on 2005-04-27 at 02:49:17ID: 13874302

Check for your RPC services is running and RPC service in remote machien is running?

 

by: testnPosted on 2005-04-27 at 04:43:02ID: 13874998

make sure that
1. firewall is off (to allow RPC)
2. two servers are in the same domain
3. account that use to run that code must be able to authenticate on the other server
4. and have permission enough to get that data

very likely that it has something to do with sp 2 since it turns firewall on by default
you may follow this instruction to carefully enable RPC port for local subnet
http://www.microforge.net/kb/39

 

by: BurntSkyPosted on 2005-04-27 at 11:34:39ID: 13879134

@ Uritsukidoji:

I hadn't thought about the possibility of it being run asynchronously.  Although, what good would that do?  The application can't move forward until the code executes and instantiates the DirectoryEntry object anyway, so why run it on a different thread?  I guess the CLR might create new threads for executing native/unmanaged code and pausing the existing thread until the new one completes...

Regardless, I'm still not able to trap the error.  I'm working with a WinForms application so I've tried attaching event handlers to the Application.ThreadException event and this is the most I can get out of it:

Exception Type:  System.Runtime.InteropServices.COMException
COMException Error code:  -2147023174
Stack Trace:
   System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is unavailable
   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_IsContainer()
   at System.DirectoryServices.ChildEnumerator..ctor(DirectoryEntry container)
   at System.DirectoryServices.DirectoryEntries.GetEnumerator()
   at xxx.xxx.xxx.CreateVirtualDirectory(String serverAddress, String virDirName, String path) <--- the method containing the code in my original post.

I just wish the message was a little more detailed.


@ dungla:

Yes, the RPC service is running (however, I'm not sure if theres a configuration issue).  Like I said before, when I execute it locally against my machine (intranet), it works fine, however, if I execute it against my external (internet) ip address it throws the aforementioned exception.


@ testn:

1. firewall is off.
2. i would assume my machine wether externally or internally would be on the same domain (i'm not really a network specialist though.  nor an active directory specialist for that matter)
3. the account should be able to authenticate... as i said above, i'm no network specialist, so i'm not sure what the exact requirements are.
4. account should have access (however, if it didn't i wouldnt expect to get the "RPC server is unavailable" message.  i would expect a permission/credentials related message).


After playing around with it some more, I'm guessing the issue isn't necessarily the code.  It might be the way my network is set up.  I'm not really sure what requirements there are for active directory.  I really just wish the exception was more detailed so i could pinpoint the issue easier.

Any more suggestions would be much appreciated.  Thanks

 

by: dunglaPosted on 2005-04-27 at 18:25:30ID: 13881985

BurntSky,

Sure, when you run the code in local machine that mean you was authorized to do that. When you run the code to create CreateVirtualDirectory at remote machine, you need to make sure that.

I already have a question about connect to remote machine in network, you can refer to it for more information

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21234441.html

You can try to connect to remote machine by call "net use \\computername" to make sure you have permission to do that. If it succeed, then you can run your code without worry anything

 

by: BurntSkyPosted on 2005-04-28 at 11:57:56ID: 13888911

Well, I guess the question is a little too complex to get a straight forward solution.  You're probably right about it being an authorization issue though.  I tried NET USE and NET VIEW, both of which work fine against my local machine, but against a remote machine I'm getting an "Access Denied" message with no prompt for a username/password.  I'm assuming this is a result of how my network and/or workstations are set up.  Maybe I'll just go pick up a book on the subject or something instead.

Thanks for the help.

 

by: dunglaPosted on 2005-04-28 at 18:40:48ID: 13891487

I think it just because your network. Maybe two computers not in the same domain (if domain controller), or both are WinXP SP2

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...