title: System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred
body: <p>I have the same web app working in three others servers. Anyone have any idea why is not working in the 4th server? See the error and stacktrace:</p>
  
  <blockquote>
    <p><em>An operations error occurred.</em></p>
    
    <p><em>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.</em></p>
    
    <p><em>Exception Details:<br>
    System.DirectoryServices.DirectoryServicesCOMException: An operations
    error occurred.</em></p>
    
    <p><em>Source Error:</em></p>
    
    <p><em>An unhandled exception was generated during the execution of the
    current web request. Information regarding the origin and location of
    the exception can be identified using the exception stack trace below.</em></p>
    
    <p><em>Stack Trace:</em></p>
    
    <p><em>[DirectoryServicesCOMException (0x80072020): An operations error
    occurred. ]    System.DirectoryServices.DirectoryEntry.Bind(Boolean
    throwIfFail) +454    System.DirectoryServices.DirectoryEntry.Bind()
    +36    System.DirectoryServices.DirectoryEntry.get_AdsObject() +31    System.DirectoryServices.PropertyValueCollection.PopulateList() +22<br>
    System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry
    entry, String propertyName) +96<br>
    System.DirectoryServices.PropertyCollection.get_Item(String
    propertyName) +142
    System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()
    +1134    System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
    +37    System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
    +124    System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()
    +31    System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext
    context, Type principalType, Nullable'1 identityType, String
    identityValue, DateTime refDate) +14<br>
    System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext
    context, Type principalType, String identityValue) +73<br>
    System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext
    context, String identityValue) +25<br>
    Infraero.TINE3.STTEnterprise.Web.Common.Seguranca.ServicoAutenticacao.EfetuarLogin(AcessoUsuario
    acessoUsuario, String senha) in
    D:\SVN\STT\trunk\4-0_CodigoFonte_Enterprise\4-4_SRC\Infraero.TINE3.STTEnterprise.Web\Common\Seguranca\ServicoAutenticacao.cs:34
    Infraero.TINE3.STTEnterprise.Web.Controllers.LoginController.ValidarUsuarioAD(String
    matricula, String senha, AcessoUsuario acessoUsuario) in
    D:\SVN\STT\trunk\4-0_CodigoFonte_Enterprise\4-4_SRC\Infraero.TINE3.STTEnterprise.Web\Controllers\LoginController.cs:92
    Infraero.TINE3.STTEnterprise.Web.Controllers.LoginController.ValidarUsuario(String
    matricula, String senha) in
    D:\SVN\STT\trunk\4-0_CodigoFonte_Enterprise\4-4_SRC\Infraero.TINE3.STTEnterprise.Web\Controllers\LoginController.cs:80
    Infraero.TINE3.STTEnterprise.Web.Controllers.LoginController.Index(LoginViewModel
    loginViewModel) in
    D:\SVN\STT\trunk\4-0_CodigoFonte_Enterprise\4-4_SRC\Infraero.TINE3.STTEnterprise.Web\Controllers\LoginController.cs:54
    lambda_method(Closure , ControllerBase , Object[] ) +108<br>
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase
    controller, Object[] parameters) +17<br>
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext
    controllerContext, IDictionary'2 parameters) +208<br>
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext
    controllerContext, ActionDescriptor actionDescriptor, IDictionary'2
    parameters) +27<br>
    System.Web.Mvc.&lt;>c__DisplayClass15.b__12()
    +55    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter
    filter, ActionExecutingContext preContext, Func'1 continuation) +263<br>
    System.Web.Mvc.&lt;>c__DisplayClass17.b__14()
    +19    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext
    controllerContext, IList'1 filters, ActionDescriptor actionDescriptor,
    IDictionary`2 parameters) +191<br>
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
    controllerContext, String actionName) +343<br>
    System.Web.Mvc.Controller.ExecuteCore() +116<br>
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
    +97    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext
    requestContext) +10<br>
    System.Web.Mvc.&lt;>c__DisplayClassb.b__5() +37<br>
    System.Web.Mvc.Async.&lt;>c__DisplayClass1.b__0() +21<br>
    System.Web.Mvc.Async.&lt;>c__DisplayClass8'1.b__7(IAsyncResult
    _) +12    System.Web.Mvc.Async.WrappedAsyncResult'1.End() +62    System.Web.Mvc.&lt;>c__DisplayClasse.b__d() +50<br>
    System.Web.Mvc.SecurityUtil.b__0(Action f) +7 
    System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
    +22    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60<br>
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult
    result) +9<br>
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    +8963149    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +184</em></p>
  </blockquote>
  
  <p>EfetuarLogin Method:</p>
  
  <pre><code>public static bool EfetuarLogin(User user, string password)
  {
      bool isValid = false;
  
      if (user != null)
      {
          PrincipalContext context = new PrincipalContext(ContextType.Domain);
  
          using (context)
          {
              isValid = context.ValidateCredentials(user.Login, password);
  
              if (isValid)
              {
                  UserPrincipal userAD = UserPrincipal.FindByIdentity(context, user.Login);
  
                  MySession.CurrentUser = new MyUserSession()
                  {
                      Id = user.Id,
                      ProfileId = user.ProfileId ,
                      Login = user.Login ,
                      Name = userAD.Name
                  };
              }
          }
      }
  
      return isValid;
  }
  </code></pre>