We have a winforms application that gets the groups from the active directory. Now everything worked fine till we have exchanged the old domaincontroller with a new one.
Since then, our application throws an exception when the method UserPrincipal.GetGroups() is called. The Exception is thrown because it tries to connect to the old DC.
The Exception message translated:
The Server is not operational surottdc04.TOSOT.CH
Does anyone have any idea, if the old dc-information is cached somewhere or where does the application get the old information?
In the following screenshot, you can see the code-section where the Exception is thrown:
As you can see, in the watch window, there is the correct new DC surottdc06, this was propably taken from the context of the current logged user. But in the Exception, there is still the old DC surottdc04, why?
UPDATE
So far we have found out that when we pass the context as paramter to the method, then it works but without the context, the method tries to connect to the old DC.
This is one possible solution, but the question is still, where does the method get the old DC information and tries to connect there, when the method is called parameterless?
public void GetGroups()
{
var sid = WindowsIdentity.GetCurrent().User.Value;
using (var context = new PrincipalContext(ContextType.Domain, "tosot.ch"))
{
using (var userPrinciple = UserPrincipal.FindByIdentity(context, sid))
{
/*
* this works, we just pass the context which we've used to
* create the UserPrincipal instance again to fetch the groups
*/
var ret = userPrinciple.GetGroups(context);
/*
* this works NOT: when calling without context argument,
* it seems, the context used is not the same
* as the userPrinciple instance is linked to.
* Instead it uses a selfmade context with an yet exsting,
* but currently not online domain controller - why that??
* (this 'old' domain controller is currently not running,
* but it's yet not removed from the domain ...)
*/
ret = userPrinciple.GetGroups();
}
}
}