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 8639317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:58:14+00:00 2026-06-12T10:58:14+00:00

I Have created one UnitTesting Project in C# and facing some issues. Firstly, I

  • 0

I Have created one UnitTesting Project in C# and facing some issues.

Firstly, I wanted to do some Connect functionality that should happen only once in the beginning.
After that i am trying to read some records from Excel file and testing some insert operations and each time insert happens TestCleanUp() gets fired after that constructor gets called then Initialize method.
I dont want constructor to get fire after each record is inserted only once.
I am confused where to put my Connect functionality and how to avoid calling constructor every time.

[TestClass]
    public class TestConnection
    {
        private TestContext testContextInstance;
        private static iCAM70003SDKC o_DeviceControl = null;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }



        [ClassInitialize()]   
        public static void Initialize()
        {

            int iResult = 0;
            EOperationalMode OperationalMode;



        }

Now i am able to make a initial connection in ClassInitialize as suggested.
Now as i am creating instance of my COM object in ClassInitialize now making initial connection.
Now i have different Testmethod to be tested .
Now when i run my program i get Exception after executing first testmethod “COM object that has been separated from its underlying RCW cannot be used”?

I guess when it is trying to execute second testmethod COM object is getting destroyed.
How to keep this COM object alive ?
I am not calling ReleaseCOMObject.

  • 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-06-12T10:58:16+00:00Added an answer on June 12, 2026 at 10:58 am

    You can make a static method decorated with [ClassInitalize] which will only run once for the test class. This is a great place to establish an initial connection.

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

Sidebar

Related Questions

I have created one library project, in that i am trying to Twitter sharing.
I have created one service in my grails application. in that service 25 methods
I have created one library project in iphone and my images folder is present
i have created one image but problem is that when i save image from
i have created one login and register view in that view after login user
I have created one aspx Page from that i need to access the property
I have created one small GEF project which contains the GEF editor. Now I
I have created one preference page where there are stringfieldeditor. Whenever user give some
I have created one UIImageView Here's code capView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kARROW_CAP_NAME]]; capView.frame
I have created one class as public class FormActivity extends Activity { TextView tv

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.