Showing posts with label System.DirectoryServices.AccountManagement. Show all posts
Showing posts with label System.DirectoryServices.AccountManagement. Show all posts

Thursday, April 7, 2016

System.DirectoryServices.DirectoryServicesCOMException: A local error has occurred.

Problem:

Running an MVC 5 based solution which is using AD on prem for ID control.  This solution depends on the UserPrincipal call to get a user.  The error was occurring in code on this line

UserPrincipal user = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, windowsaccountname);

It worked fine yesterday but just stopped working.

Solution:

Step 1:

Checked with our Admin staff and confirmed that a GPO had been applied against all accounts to include service accounts.  The IIS app pool is using a service account to connect to the database.
The policy turned on Smart card required property for the service account

Smart Card option active







The obvious issue is that a service account is not going to use a smart card.  So solution was to disable the smart card action and restart application pool.

Remove Smart card requirement

Step 2:

Now getting this error!

 Not to worry this can be resolved by resetting the password in Active Directory

 
Change Password

 Step 3:

Now go to IIS and reset password on application pool for the web application

Add user name and password you changed in Step 2.

 Done!

Source:

http://fetchmytip.blogspot.com/2016/02/cac-piv-adfs-ldap-oh-my.html

Wednesday, February 24, 2016

Attempted to access an unloaded appdomain. (Exception from HRESULT: 0x80131014)

Problem:

Using MVC 5 application and the namespace System.DirectoryServices.AccountManagement.
I kept getting this error intermittently running my app.  Looks like an issue in ADSI which is a bit buggy. 

Solution:

Tofumaster's suggestion of adding the domain string to the principal context seems to have done the trick for me. 

instead of

PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

do this

PrincipalContext ctx = new PrincipalContext(ContextType.Domain,"MyDomain");



Source:

  1. http://stackoverflow.com/questions/6605666/querying-active-directory-from-mvc-result-in-attempted-to-access-an-unloaded-ap
  2. http://forums.asp.net/t/1697428.aspx?Querying+Active+Directory+from+MVC+result+in+Attempted+to+access+an+unloaded+appdomain+Exception+from+HRESULT+0x80131014+
  3. http://stackoverflow.com/questions/5895128/attempted-to-access-an-unloaded-appdomain-when-using-system-directoryservices