Hi
All C# ADSI samples that I run cause unspecified errors. If I
translate them into VB.NET they run fine.
Here's an example:
public string getEmail(string LDAPPath, string username)
{
DirectoryEntry entry = new DirectoryEntry( LDAPPath);
DirectorySearch er mySearcher = DirectorySearch er(entry);
mySearcher.Prop ertiesToLoad.Ad d("mail");
mySearcher.Filt er =
("&(objectClass =user)(sAMAccou ntName="+userna me+")");
StringBuilder sb = new StringBuilder() ;
foreach (SearchResult result in mySearcher.Find All())
sb.Append(resul t.Properties["0"].ToString());
return(sb.ToStr ing());
}
results in:
Unspecified error
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Runtime. InteropServices .COMException:
Unspecified error
Source Error:
Line 41: StringBuilder sb = new StringBuilder() ;
Line 42:
Line 43: foreach (SearchResult result in mySearcher.Find All())
Line 44: sb.Append(resul t.Properties["0"].ToString());
Line 45:
Source File: c:\inetpub\wwwr oot\area51\adsi \webform6.aspx. cs Line:
43
Stack Trace:
[COMException (0x80004005): Unspecified error]
System.Director yServices.Direc toryEntry.Bind( Boolean throwIfFail)
+704
System.Director yServices.Direc toryEntry.Bind( ) +10
System.Director yServices.Direc toryEntry.get_A dsObject() +10
System.Director yServices.Direc torySearcher.Fi ndAll(Boolean
findMoreThanOne ) +198
System.Director yServices.Direc torySearcher.Fi ndAll() +10
area51.ADSI.Web Form6.getEmail( String LDAPPath, String username) in
c:\inetpub\wwwr oot\area51\adsi \webform6.aspx. cs:43
area51.ADSI.Web Form6.Page_Load (Object sender, EventArgs e) in
c:\inetpub\wwwr oot\area51\adsi \webform6.aspx. cs:28
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +67
System.Web.UI.C ontrol.LoadRecu rsive() +35
System.Web.UI.P age.ProcessRequ estMain() +750
I'm using "<identity impersonate="tr ue" />" in the web config file.
Any ideas why I can use DirectorySearch er from VB but not from C#? 5 24728
>public string getEmail(string LDAPPath, string username) { DirectoryEntry entry = new DirectoryEntry( LDAPPath);
DirectorySearch er mySearcher = DirectorySearch er(entry);
mySearcher.Prop ertiesToLoad.Ad d("mail"); mySearcher.Filt er = ("&(objectClas s=user)(sAMAcco untName="+usern ame+")");
StringBuilder sb = new StringBuilder() ;
foreach (SearchResult result in mySearcher.Find All()) sb.Append(resul t.Properties["0"].ToString());
First of all, it should be
sb.Append(resul t.Properties[0].ToString());
If you have the 0 in double quotes, you're trying to access a property
by the name of "0" which doesn't exist, so you get back a NULL value,
which you try to cast by calling .ToString() - but you're calling that
on a NULL value, hence the error.
Also - if that particular user's "mail" attribute is NOT set, then
you'll get back a NULL value for the .Properties[0], too, which you
can't just call a .ToString() on either.
VB.NET probably shields you from those programming errors by some
means of a default behaviour - in C#, you need CHECK for those NULL
values!
Marc
=============== =============== =============== =============== ====
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)i nova.ch
Thanks for the response Mark. I found a stupid error in the LDAP
string I was passing where I wasn't appending "LDAP":
DirectoryEntry oRootDSE = new DirectoryEntry( "LDAP://RootDSE");
string LDAPPath = oRootDSE.Proper ties["defaultNamingC ontext"][0].ToString();
which I fixed. But I missed the double quotes and null possibility.
if (result.Propert ies["mail"][0] != null)
sb.Append(resul t.Properties["mail"][0].ToString());
....now works, thanks again. If you have the 0 in double quotes, you're trying to access a property by the name of "0" which doesn't exist, so you get back a NULL value, which you try to cast by calling .ToString() - but you're calling that on a NULL value, hence the error.
Also - if that particular user's "mail" attribute is NOT set, then you'll get back a NULL value for the .Properties[0], too, which you can't just call a .ToString() on either.
VB.NET probably shields you from those programming errors by some means of a default behaviour - in C#, you need CHECK for those NULL values!
Marc =============== =============== =============== =============== ==== Marc Scheuner May The Source Be With You! Bern, Switzerland m.scheuner(at)i nova.ch
>which I fixed. But I missed the double quotes and null possibility. if (result.Propert ies["mail"][0] != null) sb.Append(resul t.Properties["mail"][0].ToString());
Actually, I almost think you'd have to change this to:
if (result.Propert ies["mail"] != null)
sb.Append(resul t.Properties["mail"][0].ToString());
You see - if the "mail" attribute is not set, then the
..Properties["mail"] is already null, and indexing that by [0] will
cause an exception.
Marc
=============== =============== =============== =============== ====
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)i nova.ch
I have been searching for the solution to the same error,
but I think it may be related to the DirectoryEntry( )
call.
When I explicitly specify the DirectoryEntry parameters
it works fine, when I try to use a variable (LDAPQuery)
it fails. The string is being created properly as I can
assign it to a label and have it output correctly.
Any clues?
Code:
// Create AD LDAP search objects
LDAPQuery = string.Format(" \"LDAP://{0}\", \"{1}\", \"{2}
\"", domain, UsrName, UsrPass);
// This does not work
DirectoryEntry SearchRoot = new DirectoryEntry( LDAPQuery);
// This works
// DirectoryEntry SearchRoot = new DirectoryEntry
("LDAP://testdomain", "fubarjones ", "Testing@9" );
Jay -----Original Message-----public string getEmail(string LDAPPath, string
username){ DirectoryEntry entry = new DirectoryEntry
(LDAPPath); DirectorySearch er mySearcher = DirectorySearch er
(entry); mySearcher.Prop ertiesToLoad.Ad d("mail"); mySearcher.Filt er = ("&(objectCla ss=user)(sAMAcc ountName="+user name+")");
StringBuilder sb = new StringBuilder() ;
foreach (SearchResult result in mySearcher.Find All
()) sb.Append(resul t.Properties["0"].ToString
()); First of all, it should be
sb.Append(resul t.Properties[0].ToString
()); If you have the 0 in double quotes, you're trying to
access a propertyby the name of "0" which doesn't exist, so you get back
a NULL value,which you try to cast by calling .ToString() - but
you're calling thaton a NULL value, hence the error.
Also - if that particular user's "mail" attribute is NOT
set, thenyou'll get back a NULL value for the .Properties[0],
too, which youcan't just call a .ToString() on either.
VB.NET probably shields you from those programming
errors by somemeans of a default behaviour - in C#, you need CHECK for
those NULLvalues!
Marc ============== =============== =============== =============
=======Marc Scheuner May The Source Be
With You!Bern, Switzerland m.scheuner(at)
inova.ch.
>When I explicitly specify the DirectoryEntry parameters it works fine, when I try to use a variable (LDAPQuery) it fails. The string is being created properly as I can assign it to a label and have it output correctly.
// Create AD LDAP search objects LDAPQuery = string.Format(" \"LDAP://{0}\", \"{1}\", \"{2} \"", domain, UsrName, UsrPass);
What EXACTLY is in the LDAPQuery string in the end here???
// This does not work DirectoryEnt ry SearchRoot = new DirectoryEntry( LDAPQuery);
If it doesn't work, then most likely your LDAP string is invalid /
incomplete.
Marc
=============== =============== =============== =============== ====
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)i nova.ch This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andrej |
last post by:
hi,
i must skip throug all of my contacts in AD and check if targetAddress =
entry in the array of ProxyAddress.
DirectorySearcher.FindAll() methode returns just 1000 elemets, but i have
much more contacts to loop throug in AD. how can i get all of the contacts? i
tried to set the sizelimit of my searcher to 100.000 but the find all method
returnd just 1.000 objects.
|
by: Hin |
last post by:
I often encounter the following when i try to view the form in VS.NET 2003:
An error occurred while loading the document. Fix the error, and then try
loading the document again. The error message follows:
Unspecified error
Anyone know the possible causes or how to fix this?
Thanks!
|
by: RM |
last post by:
Had VS .Net 2002 installed on W2k Server SP3 and supported
a number of web sites. Installed VS .Net 2003 on Friday and now
all web sites using .Net & MS ACCESS get this strange error upon open.
ASP=/TestDotNet/AdoNet.aspx
System.Data.OleDb.OleDbException: Unspecified error at
System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr)
at System.Data.OleDb.OleDbConnection.InitializeProvider()
at System.Data.OleDb.OleDbConnection.Open()...
|
by: Jim Lacenski |
last post by:
I have a VB class that uses .NET and ADODB to write into
an Excel spreadsheet (via Jet) on a server as part of a
web application. ADODB is used instead of ADO.NET because
it greatly simplifies the write process, and is supported
for use on a server. (Excel is not supported (1),
licensing issues with OWC). The routine works fine for a
user at the server, but when a user from a system other
than the server runs the page the error...
|
by: T8 |
last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by itself (asp.net recycled?); it also can be solved by restarting IIS.
Any ideas what cause(s) this to happen?
System.Data.OleDb.OleDbException: Unspecified error
at System.Data.OleDb.OleDbDataReader.ProcessResults(Int32 hr)
at...
| |
by: GotdotNet |
last post by:
I get this error once in a while and I normally could fix it by restarting IIS. However, I would like to find out what causes this. Can anyone help?
-----------------------------error screen-----------------------------------
System.Data.OleDb.OleDbException: Unspecified error
at System.Data.OleDb.OleDbDataReader.ProcessResults(Int32 hr)
at System.Data.OleDb.OleDbDataReader.GetRowHandles()
|
by: Siegfried Heintze |
last post by:
I'm using a third party hosting service. I presently have a Web Service on
this hosting service's server that loads and executes a native mode DLL.
This demonstrates that the hosting service has given me proper access to the
temporary directory c:/Windows/Microsoft.NET/Framework/V1.1.4322/Temporary
ASP.NET Files/root/...."
I believe it also demonstrates that I have access to c:/documents and
settings/xyz/aspnet/local settings/
...
|
by: sjoshi |
last post by:
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");
}
|
by: Jonathan |
last post by:
Hi Everyone,
I have a problem which I've been able to reproduce with a nice and
small test ASP.NET web application. The page sets the
window.onbeforeunload event so that we will get an Ok/Cancel dialog box
to prompt users before navigating away from the page. There are many
different types of input buttons on the page (e.g. asp:Button,
asp:ImageButton, asp:LinkButton, asp:DropDownList, asp:CheckBox) and
most of them work fine. However,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |