System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred

后端 未结 7 789
南笙
南笙 2020-12-01 04:08

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:

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 05:01

    So if you place a breakpoint on the line:

    UserPrincipal userAD = UserPrincipal.FindByIdentity(context, user.Login);
    

    and step through it, it generates the above exception which does not have any InnerExceptions?

    According to the stack trace, that line is the beginning of the problem. The returned exception should have at least some other information in it as to why it was thrown.

    InnerException Concatenator

    The following method takes the top level exception and returns a tab and linebreak formatted breakdown of the inner exceptions as a string.

        private static string InnerExceptionConcatenator(Exception ex, int tabTracker = 0)
        {
            string retVal = "";
            if (ex.InnerException != null)
            {
                tabTracker ++;
                retVal = string.Format( "{0}\r\n{1}{2}", ex.Message, new String('\t', tabTracker), InnerExceptionConcatenator(ex.InnerException));
            }
            else
            {
                retVal = ex.Message;
            }
            return retVal;
        }
    

    You can call it thusly:

    try
    {
    
    }
    catch(ex Exception)
    {
        var exceptionString = InnerExceptionConcatenator(ex);
        var path = @"c:\temp\exception.txt";
        if (!File.Exists(path)) 
        {
            using (StreamWriter sw = File.CreateText(path)) 
            {
                sw.WriteLine(exceptionString);
            }   
        }
        else
        {
            using (StreamWriter sw = File.AppendText(path)) 
            {
                sw.WriteLine(exceptionString);
            }
        }
    }
    

提交回复
热议问题