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

  • SEARCH
  • Home
  • 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 6749915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:44:49+00:00 2026-05-26T12:44:49+00:00

Presently I am attempting to create unit tests using MSTest.exe for multithreading functionality. When

  • 0

Presently I am attempting to create unit tests using MSTest.exe for multithreading functionality. When I run the tests, here are the errors I’m getting:

A first chance exception of type 'System.NullReferenceException' occurred in ApplicationManagement.exe
The thread 'Agent: adapter run thread for test 'UpdateDirectoryExceptionTest' with id 'a78d3e8e-e859-43aa-87aa-cf006f736dee'' (0x1150) has exited with code 0 (0x0).
The thread '<No Name>' (0x1bec) has exited with code 0 (0x0).
E, 6788, 86, 2011/10/20, 14:02:36.771, WKSTVMC0006\QTAgent32.exe, Unhandled Exception Caught, reporting through Watson: System.NullReferenceException: Object reference not set to an instance of an object.
   at CommonObjects4.clsThread.StartThreadMethod.Execute() in D:\DevProjects\CommonObjects4\classes\clsThread.cs:line 23
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
The program '[6788] QTAgent32.exe: Managed (v4.0.30319)' has exited with code -2 (0xfffffffe).
The program '[1120] ApplicationManagement.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

If I run the UpdateDirectoryExceptionTest by itself in Visual Studio, it passes with no problem, but when I run the entire suite of unit tests, I receive the above error. Here is the function that I recently started testing, which I think is related to the error:

    public Thread StartClassThread(ref Thread ThreadObject, ThreadMethod MethodObject)
    {
        System.Threading.Thread startClassThreadReturn = null;
        try
        {
            if (ThreadObject == null && MethodObject == null)
            {
                throw new ApplicationException("Cannot have both ThreadObject and MethodObject as null parameters in call to StartClassThread.");
            }
            StartThreadMethod objMethod = new StartThreadMethod();
            objMethod.objThreadMethod = MethodObject;
            if (!(ThreadObject == null))
            {
                if (ThreadObject.ThreadState != System.Threading.ThreadState.Stopped)
                {
                    // Do nothing
                }
            }
            if (!(ThreadObject == null))
            {
                if (ThreadObject.ThreadState == System.Threading.ThreadState.Stopped 
                    | ThreadObject.ThreadState == System.Threading.ThreadState.Aborted
                    | ThreadObject.ThreadState == System.Threading.ThreadState.Unstarted) 
                { 
                    ThreadObject = null; 
                    ThreadObject = new Thread( new System.Threading.ThreadStart( objMethod.Execute ) ); 
                    ThreadObject.Start(); 
                } 
            } 
            else 
            { 
                ThreadObject = new Thread( new System.Threading.ThreadStart( objMethod.Execute ) ); 
                ThreadObject.Start(); 
            } 
            return ThreadObject; 
        } 
        catch (Exception excException) 
        { 
            ZEGApp.clsMain.objApplicationAudit.AuditMethodError(excException, System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " - " + excException.StackTrace);
        }
        finally 
        { 
            // Do nothing
        } 
        return startClassThreadReturn;
    } 

Here is the output I receive from CruiseControl.NET, as opposed to testing within Visual Studio:

  <message>Passed                UnitTests.clsThreadTest.StartClassThreadTest2</message>
  <message>Process 'QTAgent32' [PID 3932] has finished profiling.</message>
  <message>Process 'QTAgent32' [PID 5388] has begun profiling.</message>
  <message>Error                 UnitTests.clsUltraCalendarTest.clsUltraCalendarConstructorTest</message>

Does anyone have any ideas as to how I can resolve these errors? TIA.

UPDATE: Here is the full source code for clsThread.cs (please note that line 23 is objThreadMethod(); ):

namespace CommonObjects4
{
    public class clsThread
    {

    #region '" Sub Class "'

    public delegate void ThreadMethod();

    private class StartThreadMethod  
    { 
        public ThreadMethod objThreadMethod; 
        public void Execute() 
        { 
            objThreadMethod(); // this is line 23
        }
    }

    #endregion

    #region '" Enumerator Declaration "'
    #endregion

    #region '" Variable Declaration "'
    #endregion

    #region '" Property Declaration "'
    #endregion

    #region '" Function Declaration "'

    public Thread StartClassThread(Thread ThreadObject, ThreadMethod MethodObject)
    {
        System.Threading.Thread startClassThreadReturn = null;
        try
        {
            if (ThreadObject == null && MethodObject == null)
            {
                throw new ApplicationException("Cannot have both ThreadObject and MethodObject as null parameters in call to StartClassThread.");
            }
            StartThreadMethod objMethod = new StartThreadMethod();
            objMethod.objThreadMethod = MethodObject;
            if (!(ThreadObject == null))
            {
                if (ThreadObject.ThreadState != System.Threading.ThreadState.Stopped)
                {
                    // Do nothing
                }
            }
            if (!(ThreadObject == null))
            {
                if (ThreadObject.ThreadState == System.Threading.ThreadState.Stopped | ThreadObject.ThreadState == System.Threading.ThreadState.Aborted ) 
                { 
                    ThreadObject = null; 
                    ThreadObject = new Thread( new System.Threading.ThreadStart( objMethod.Execute ) ); 
                    ThreadObject.Start(); 
                } 
            } 
            else 
            { 
                ThreadObject = new Thread( new System.Threading.ThreadStart( objMethod.Execute ) ); 
                ThreadObject.Start(); 
            } 
            return ThreadObject; 
        } 
        catch (Exception excException) 
        { 
            ZEGApp.clsMain.objApplicationAudit.AuditMethodError(excException, System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " - " + excException.StackTrace);
        }
        finally 
        { 
            // Do nothing
        } 
        return startClassThreadReturn;
    } 

    #endregion 

} 
}
  • 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-26T12:44:49+00:00Added an answer on May 26, 2026 at 12:44 pm

    The problem would appear to be that objThreadMethod is null at line 23. The syntax objThreadMethod() is actually shorthand for objThreadMethod.Invoke(), so you’ll get a NullReferenceException if objThreadMethod is null when the line is executed.

    As for why it’s null, I’m guessing that you’ve invoked the StartClassThread method with a non-null ThreadObject and a null MethodObject, which resulted in the following block being executed after setting objMethod.objThreadMethod to the null MethodObject:

    ThreadObject = null;
    ThreadObject = new Thread( new System.Threading.ThreadStart( objMethod.Execute ) );
    ThreadObject.Start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Presently I'm starting to introduce the concept of Mock objects into my Unit Tests.
I'm attempting to profile junit tests in eclipse on OSX using TPTP . I
I run (and am presently completely overhauling) a website that deals with theater (njtheater.com
I am attempting to create a Tab Control Style that basically looks like buttons
I am attempting to the read-in a .txt file and create a map to
Here is where I am at presently. I am designing a card game with
I'm attempting to create a hierarchal menu system in rails. My menu model is
I'm attempting to create a template system where an uploaded jpg is then placed
I am attempting to make a HTTPS connection to a website using HttpsURLConnection ,
I'm presently attempting to write a few classes to aid me in writing various

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.