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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:30:10+00:00 2026-05-12T05:30:10+00:00

BACKGROUND I am automating an PowerPoint 2007 via C# I am writing unittests using

  • 0

BACKGROUND

  • I am automating an PowerPoint 2007 via C#
  • I am writing unittests using the built-in unit testing of Visual Studio (Microsoft.VisualStudio.TestTools.UnitTesting) for my code
  • I am well relatively experienced in automating the Office 2007 apps

MY PROBLEM

  • When I run my unit tests, the first unit test method runs fine, all after that have an error concerning a detached RCW
  • I am creating a static instance of PowerPoint for the test methods to share, but it seems like the application RCW is getting detached after the first test method is run

THE SOURCE CODE

    using System;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    namespace TestDemo
    {



        [TestClass]
        public class UnitTest1
        {
            private static Microsoft.Office.Interop.PowerPoint.ApplicationClass 
              g_app = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();

            private TestContext testContextInstance;

            public TestContext TestContext
            {
                get
                {
                    return testContextInstance;
                }
                set
                {
                    testContextInstance = value;
                }
            }



            [TestMethod]
            public void Test01()
            {
                g_app.Visible = Microsoft.Office.Core.MsoTriState.msoCTrue;
            }

            [TestMethod]
            public void Test02()
            {
                g_app.Visible = Microsoft.Office.Core.MsoTriState.msoCTrue;
            }
        }

    }

THE ERROR MESSAGE

Test method TestDemo.UnitTest1.Test02 threw exception:
System.Runtime.InteropServices.InvalidComObjectException: COM 
object that has been separated from its underlying RCW cannot be used..

This message comes on the line where the PowerPoint instance is used (when I set the Visible property)

WHAT I HAVE TRIED

  • The order of the unittests does not change the behavior
  • The same problem occurs with Word 2007, Visio 2007, etc.
  • When writing testcases with NUNIT I don’t get these problem – obviously something is different about how visual studio runs unit tests (not implying VS is incorrect, just pointing out it is different from NUNIT)
  • It has nothing to do with the Visible property – any usage of a method or property will cause this issue
  • I have tried using the attributes AssemblyInitialize and ClassInitialize to create the instance but nothing has worked
  • Googled & Binged – no clear answer that helps me

COMMENTS

  • I could switch to NUNIT, but would prefer to keep using Visual Studio’s native unit test framework

MY QUESTION

  • How can I successfully create an single instance of PowerPoint 2007 that will be shared among all the TestMethods
  • If you can provide insight into why this is happening, I would be grateful.

SOLVED (THANKS TO ALCONJA)

  • I followed his advice to modify the .testrunconfig and it worked.

LINKS

  • http://blogs.msdn.com/martijnh/archive/2009/12/31/unit-testing-com-object-that-has-been-separated-from-its-underlying-rcw-cannot-be-used.aspx
  • 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-12T05:30:10+00:00Added an answer on May 12, 2026 at 5:30 am

    Looks like the issue is that MS Unit Tests run in multiple threads whereas NUnit tests run in the same thread. So the static reference to PowerPoint when running in your MS tests is being shared between threads, which COM doesn’t like since by default its STA (single threaded). You can switch MS test to use MTA (multi-threading for COM) by adding:

    <ExecutionThread apartmentState="MTA" />
    

    to your *.testrunconfig file (open the file as XML & chuck the above line anywhere in main the TestRunConfiguration node).

    Not sure how well PowerPoint (& your specific tests) will deal with being treated as being multi-threaded, but your trivial example above passes with MTA switched on. If you do get threading issues occurring, you could try making your unit tests ordered & see if that fixes the issue.

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

Sidebar

Related Questions

Background I am automating some Office application (Word and PowerPoint) via command-line tool. One
Background: Using unix, codeigniter from localhost. I'd like to run a controllers via a
Background: I'm using the (fantastic) Vim plugin python-mode , which includes the pep8 linter.
Background - I am using paramiko to put files on a bunch of remote
Background I am working with a monad built of a stack of transformers one
Coming from .NET background ... Is there a way to either via key stroke
Background: I'm writing ASP.NET MVC 3 Web app. I have a List<MyObject> (actually several
Background - I am using automatic reference counting on a project. The root view
Background I have been working towards automating my Selenium test suite that I developed
I'm using a background image for a submit button that I've using for a

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.