© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
25 replies
Wolfman

Unhandled Exception: System.Runtime.InteropServices.COMException:Unknown error (0x8007203b)

I am currently working on a console app that goes through active directory and exports all the computer object to a csv document. This is what I have so far however I keep getting the error noted above when I hit around 3 million computers. Any help would be great!

using System;
using System.DirectoryServices;
using System.IO;

class Program
{
    static void Main()
    {
        string ldapPath = "";
        string csvFile = "AD_Computers.csv";

        using (StreamWriter writer = new StreamWriter(csvFile))
        {
            writer.WriteLine("Name,SerialNumber");

            using (DirectoryEntry entry = new DirectoryEntry(ldapPath))
            {
                using (DirectorySearcher searcher = new DirectorySearcher(entry))
                {
                    searcher.ServerTimeLimit = new TimeSpan(1,0,0);
                    searcher.Filter = "(objectCategory=computer)";
                    searcher.PropertiesToLoad.Add("name");
                    searcher.PropertiesToLoad.Add("serialNumber");

                    foreach (SearchResult result in searcher.FindAll())
                    {
                        string name = result.Properties["name"][0].ToString();
                        string serialNumber = result.Properties.Contains("serialNumber") ? result.Properties["serialNumber"][0].ToString() : "";

                        writer.WriteLine($"{name},{serialNumber}");
                    }
                }
            }
        }

        Console.WriteLine($"AD computers exported to {csvFile}");
    }
}
using System;
using System.DirectoryServices;
using System.IO;

class Program
{
    static void Main()
    {
        string ldapPath = "";
        string csvFile = "AD_Computers.csv";

        using (StreamWriter writer = new StreamWriter(csvFile))
        {
            writer.WriteLine("Name,SerialNumber");

            using (DirectoryEntry entry = new DirectoryEntry(ldapPath))
            {
                using (DirectorySearcher searcher = new DirectorySearcher(entry))
                {
                    searcher.ServerTimeLimit = new TimeSpan(1,0,0);
                    searcher.Filter = "(objectCategory=computer)";
                    searcher.PropertiesToLoad.Add("name");
                    searcher.PropertiesToLoad.Add("serialNumber");

                    foreach (SearchResult result in searcher.FindAll())
                    {
                        string name = result.Properties["name"][0].ToString();
                        string serialNumber = result.Properties.Contains("serialNumber") ? result.Properties["serialNumber"][0].ToString() : "";

                        writer.WriteLine($"{name},{serialNumber}");
                    }
                }
            }
        }

        Console.WriteLine($"AD computers exported to {csvFile}");
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

(WinUI 3) Visual State Manager throwing System.Runtime.InteropServices.COMException
C#CC# / help
2y ago
Unhandled exception. System.IO.FileNotFoundException
C#CC# / help
2y ago
Exception thrown: 'System.BadImageFormatException' in BruhCode2.dllAn unhandled exception of type '
C#CC# / help
3y ago
.NET Error Unknown SQL Exception
C#CC# / help
17mo ago