Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.DirectoryServices;
- namespace BrunoMartinsPro.TriggerErrors
- {
- public class AdErrorUtils
- {
- public void TriggerError()
- {
- //Define connection properties
- string ADConnectionString = "LDAP://AD.brunomartins.pro";
- string ADUserLogin = "BrunoMartinsPro";
- string ADUserPassword = "WoWWoWBadCommunication";
- //Create entry
- DirectoryEntry entry = new DirectoryEntry(ADConnectionString, ADUserLogin, ADUserPassword);
- //Create searcher
- DirectorySearcher searcher = new DirectorySearcher(entry);
- //Define filter
- searcher.Filter = "(SAMAccountname=" + "BrunoMartinsPro" + ")";
- //Load ad properties
- searcher.PropertiesToLoad.Add("name");
- searcher.PropertiesToLoad.Add(null);
- //Associate Directory Entry
- searcher.SearchRoot = entry;
- //Execute search
- SearchResult adUser = searcher.FindOne();
- //Execute search throws an exception:
- //'System.AccessViolationException' in System.DirectoryServices.dll
- //Attempted to read or write protected memory.This is often an indication that other memory is corrupt.
- //This happens because no property NULL exists
- }
- }
- }
Add Comment
Please, Sign In to add comment