Created
August 7, 2018 14:48
-
-
Save brunomartinspro/e8081c8fbcf8688ef593ed7d94229b2f to your computer and use it in GitHub Desktop.
Reproduce System.AccessViolationException exception when using Active Directory Searcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment