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); }
string display*For the question: where is the exception error then? What line, what is the error, and so on. - NewViewex.Messagebutex.Tostring()- NewView