Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 399193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:49:21+00:00 2026-05-12T16:49:21+00:00

Error im getting: An unhandled exception of type ‘System.StackOverflowException’ occurred in System.Management.dll My callstack:

  • 0

Error im getting:

An unhandled exception of type
‘System.StackOverflowException’
occurred in System.Management.dll

My callstack:

[Managed to Native Transition]
System.Management.dll!System.Management.ManagementScope.InitializeGuts(object
o) + 0x1a3 bytes

System.Management.dll!System.Management.ManagementScope.Initialize()
+ 0xa3 bytes
System.Management.dll!System.Management.ManagementScope.Connect()
+ 0x5 bytes
Computer_Managerment.exe!Computer_Managerment.WMI.ComputerInformation.ComputerInformation(string
ComputerName = “pc357”, string
UserName = “”, string Password = “”)
Line 228 + 0xd bytes C#
Computer_Managerment.exe!Computer_Managerment.ScanAllComputers.Workerthread()
Line 95 + 0x1e bytes C#
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object
state) + 0x66 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
executionContext,
System.Threading.ContextCallback
callback, object state) + 0x6f
bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()
+ 0x44 bytes

Code where i get the stackoverflow:

try
{
  gManager = new ManagementScope(ConnectStr, oConn); //\\\\" + 
  gManager.Connect(); // This is where the crash happens
}
catch (UnauthorizedAccessException)
{
  // Code removed
}

The code basicly works in this fastion
1) I have a list of all the computers in AD ( Over 1k )
2) I have 10 threads spinning a while loop getting a compuer out of the Que List.
3) When they have a computer name they make a instance of the ComputerInformation class that does the gManager.Connect(); that again crashes.

Its my understanding that this crash/stackoverflow is happening inside native code, but i assume im doing something wrong. If any more code is required il happely post it.

Pr request more code: This is the code that the workers live in ( Normaly around 10 workers )

internal struct stWorkList
{
    public Queue<string> Work;
    public List<ComputerInformation> CompInfo;
    public int FailedComputers;
    public int FailedPingCheck;
    public int SuccessComputers;
    public int TotalComputers;
    public int FailedAuth;
    public int FailedToContactWMIServer;
}
stWorkList gWorkList;

void Workerthread()
{
    Monitor.Enter(gUserName);
    Monitor.Enter(gPassword);
    string UserName = gUserName;
    string Password = gPassword;
    Monitor.Exit(gPassword);
    Monitor.Exit(gUserName);

    while (true)
    {
    Monitor.Enter(gWorkList.Work);
    if (gWorkList.Work.Count == 0)
    {
        Monitor.Exit(gWorkList.Work);
        break;
    }

    string ComputerName = gWorkList.Work.Dequeue();
    Monitor.Exit(gWorkList.Work);

    if (ComputerName == null)
        continue;

    ComputerInformation iCI = new ComputerInformation(ComputerName, UserName, Password);

    Monitor.Enter(gWorkList.CompInfo);
    gWorkList.CompInfo.Add(iCI);

    switch (iCI.Status)
    {
        case eComputerCheckStatus.Connected:
            gWorkList.SuccessComputers++;
            break;

        case eComputerCheckStatus.FailedPingTest:
            gWorkList.FailedPingCheck++;
            gWorkList.FailedComputers++;
            break;

        case eComputerCheckStatus.UnauthorizedAccessException:
            gWorkList.FailedComputers++;
            gWorkList.FailedAuth++;
            break;

        case eComputerCheckStatus.FailedToContactWMIService:
            gWorkList.FailedToContactWMIServer++;
            gWorkList.FailedComputers++;
            break;

        case eComputerCheckStatus.UnkownFailed:
            gWorkList.FailedComputers++;
            break;
    }

    Monitor.Exit(gWorkList.CompInfo);
    iCI.Dispose();
    }
}

Constructor in the ComputerInformation class

public ComputerInformation(string ComputerName, string UserName, string Password)
{
    gComputerName = ComputerName;
    gHardDriveList = new List<stHarddiskInfo>();
    gProccessInfo = new List<stProccessInfo>();
    gCPUInfo = new List<stCPUInformation>();
    gOSInfo = new stOSInfo();
    gMemoryInfo = new List<stMemoryInfo>();
    gPreformanceMemory = new stPreformanceMemory();
    gProccessOverView = new stProccessOverview();
    gMonitorInfo = new List<stMonitorInfo>();
    gNetworkInfo = new List<stNetworkInfo>();
    netMon = new Ping();

    PingResponse response = netMon.PingHost(ComputerName, 1);
    if (response == null || response.PacketsReceived == 0)
    {
        gStatus = eComputerCheckStatus.FailedPingTest;
        gHasError = true;
        return;
    }
    gComputerIP = response.ServerEndPoint.Address.ToString();

    ConnectionOptions oConn = new ConnectionOptions();
    oConn.Timeout = new TimeSpan(0, 0, 10);

    if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(UserName))
    {
        oConn.Username = UserName;
        oConn.Password = Password;
    }

    string ConnectStr = "\\\\" + ComputerName + "\\root\\cimv2";
    try
    {
        gManager = new ManagementScope(ConnectStr, oConn); //\\\\" + 
        gManager.Connect();     // this is where it crashes
    }
    catch (UnauthorizedAccessException)
    {
        gStatus = eComputerCheckStatus.UnauthorizedAccessException;
        gHasError = true;
        return;
    }
    catch (Exception Ex)
    {
    if (Ex.Message.Contains("The RPC server is unavailable"))
    {
        gStatus = eComputerCheckStatus.FailedToContactWMIService;
    }
    else
        gStatus = eComputerCheckStatus.UnkownFailed;

    gHasError = true;
    return;
    }

    gStatus = eComputerCheckStatus.Connected;

    try
    {
        GetRunningProccessInfo();
        GetCPUInformation();
        GetHardDriveInfo();
        GetOSInfo();
        GetMemoryInfo();
        GetMonitorInfo();
        GetComputerSystem();
    }
    catch
    {
        gStatus = eComputerCheckStatus.UnkownFailed;
        gHasError = true;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T16:49:21+00:00Added an answer on May 12, 2026 at 4:49 pm

    good point to start, is to check if this code is throwing exception.

            ManagementScope scope = new ManagementScope(@"\\localhost\root\cimv2");
            scope.Connect();
    

    Update
    You doesnt have Monitor.Enter/Exit block on iCI initialization (and where existing problem exception).
    to check if this is the problem you can make simple log.

      gManager = new ManagementScope(ConnectStr, oConn); 
      Debug.WriteLine("connect to "+ComputerName+" by "+UserName+"/"+Password);
      gManager.Connect();             // this is where it crashes
      Debug.WriteLine("success on "+ComputerName+" by "+UserName+"/"+Password);
    

    if my suggestion is right, you will receive in log, something like this:
    “connect to computer1”
    “connect to computer2”
    and immidiately exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 212k
  • Answers 212k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Two uses: Using directives, e.g. using System; using System.IO; using… May 12, 2026 at 10:18 pm
  • Editorial Team
    Editorial Team added an answer Take a look at HKEY_CLASSES_ROOT registry, under there are keys… May 12, 2026 at 10:18 pm
  • Editorial Team
    Editorial Team added an answer No you can't, but if you want to query based… May 12, 2026 at 10:18 pm

Related Questions

Error im getting: An unhandled exception of type 'System.StackOverflowException' occurred in System.Management.dll My callstack:
I'm getting this error from Mono's wsdl utility while trying to process eBay's WSDL
I cannot figure out why I keep getting a null ref on filename when
I have a exported function in a c++ DLL // C++ DLL (Blarggg.dll) extern
I have an application where every now and then I'm getting a strange error.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.