ADSI Query fails with unspecified error

S

sjoshi

Hello All
I'm trying this to filter group users bu tI keep getting an unspecified
error when invoking FindOne method.

Any help is greatly appreciated.

public static DirectoryEntry GetDirectoryRoot()
{
return new DirectoryEntry("LDAP://RootDSE");
}

public static string DefaultNamingCtx
{
get{
string defCtx=null;
using(DirectoryEntry rootDe = GetDirectoryRoot())
{
defCtx = rootDe.Properties["defaultNamingContext"][0].ToString();
}
return defCtx;
}
}

public static void GetGroupUsers(string groupName, ADSet dSet)
{
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = new DirectoryEntry(DefaultNamingCtx);
deSearch.Filter = string.Format("(&(objectClass=group)(cn={0}))",
groupName);
try
{
SearchResult result = deSearch.FindOne(); //***This keeps failing ***
}
catch(COMException ex)
{}
 
W

Willy Denoyette [MVP]

deSearch.SearchRoot = new DirectoryEntry("LDAP://" + defCtx);

Willy.

| Hello All
| I'm trying this to filter group users bu tI keep getting an unspecified
| error when invoking FindOne method.
|
| Any help is greatly appreciated.
|
| public static DirectoryEntry GetDirectoryRoot()
| {
| return new DirectoryEntry("LDAP://RootDSE");
| }
|
| public static string DefaultNamingCtx
| {
| get{
| string defCtx=null;
| using(DirectoryEntry rootDe = GetDirectoryRoot())
| {
| defCtx = rootDe.Properties["defaultNamingContext"][0].ToString();
| }
| return defCtx;
| }
| }
|
| public static void GetGroupUsers(string groupName, ADSet dSet)
| {
| DirectorySearcher deSearch = new DirectorySearcher();
| deSearch.SearchRoot = new DirectoryEntry(DefaultNamingCtx);
| deSearch.Filter = string.Format("(&(objectClass=group)(cn={0}))",
| groupName);
| try
| {
| SearchResult result = deSearch.FindOne(); //***This keeps failing ***
| }
| catch(COMException ex)
| {}
|
 
G

Guest

Hello,

Basically, I want my application to run only one instance at a time and pass
command line arguments to a running instance. I have all of this working, I
used the IPC Remoting channel and my program handles the command line
arguments well. However, after my program has been running for a little while
(say 5-10 minutes) the command line arguments no longer are passed, and
instead it causes a .NET Remoting exception claiming to have come across a
null reference.

So in my Program.cs file, I have something like this.

if (alreadyrunning)
{
IpcChannel ipcCh = new IpcChannel("MyProgram_" + username);
ChannelServices.RegisterChannel(ipcCh, false);

RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingService),
"Remoting", WellKnownObjectMode.Singleton);
ISharedAssemblyInterface obj = (ISharedAssemblyInterface)
Activator.GetObject(typeof(ISharedAssemblyInterface), "ipc://MyProgram_" +
username + "/Remoting");
obj.RunFirstInstance(arguments);
}
else
{
ISharedAssemblyInterface obj = (ISharedAssemblyInterface)
Activator.GetObject(typeof(ISharedAssemblyInterface), "ipc://MyProgram_" +
username + "/Remoting");
obj.HandleCommandLineArgs(arguments);
}


Again, it all works for a short time, but stops working claiming a null
reference on the HandleCommandLineArgs method after a while. I'm guessing
that even though I specifify a Singleton instance that it somehow gets
garbage collected or a new RemotingService class generated (even though my
program is still running).

Thanks in advance,
mitch
 
G

Guest

IIRC if you have a remoted object, its remoting stubs will be garbage
collected if it gets no method calls for 5 minutes. To avoid this, you
need to manage the lifetime of the remoted object. Search for
'InitializeLifetimeService', and you'll find a lot of ways to manage
the lifetime.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top