Tell me, there is an error when retrieving a user from AD: "The link to the object does not indicate an instance of the object." Although on the computer where the program is written, everything works fine, but when you run it on another computer, an error occurs.

private void SearchUser(string Login) { try { string filter = string.Format("(&(ObjectClass={0})(sAMAccountName={1}))", "person", Login); string domain = "DC=main,DC=russianpost,DC=ru"; string[] properties = new string[] { "fullname" }; DirectoryEntry adRoot = new DirectoryEntry("LDAP://" + domain, null, null, AuthenticationTypes.Secure); DirectorySearcher searcher = new DirectorySearcher(adRoot); searcher.SearchScope = SearchScope.Subtree; searcher.ReferralChasing = ReferralChasingOption.All; searcher.PropertiesToLoad.AddRange(properties); searcher.Filter = filter; SearchResult result = searcher.FindOne(); DirectoryEntry directoryEntry = result.GetDirectoryEntry(); string displayName = directoryEntry.Properties["displayName"].Value.ToString(); string displayMail = directoryEntry.Properties["mail"].Value.ToString(); string displaytelephoneNumber = directoryEntry.Properties["telephoneNumber"].Value.ToString(); byte[] data = directoryEntry.Properties["thumbnailPhoto"].Value as byte[]; MemoryStream s = new MemoryStream(data); pictureEdit1.Image = Bitmap.FromStream(s); labelControl1.Text = displayName; labelControl2.Text = "Эл.почта: " + displayMail; labelControl3.Text = "тел: " + displaytelephoneNumber; btn_UserName.Caption = displayName; } catch (Exception ex) { XtraMessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void MyForm_Load_1(object sender, EventArgs e) { SearchUser(Environment.UserName); } 
  • one
    How many letters .. but why produce so many unnecessary entities? Type string display* For the question: where is the exception error then? What line, what is the error, and so on. - NewView
  • To see the whole error stack: not ex.Message but ex.Tostring() - NewView
  • NewView Thanks, after I replaced it with ex.ToString (), I found the problem. - Arthur Chal
  • No, knowledge is power :) - NewView

0