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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:53:45+00:00 2026-05-15T19:53:45+00:00

I have a little c# class that I need to expose as COM. THe

  • 0

I have a little c# class that I need to expose as COM. THe tool that will use the COM object requires that I support STA. Is there anything special that I need to do with my COM object?

(I know about the STAThread attribute, but (unless I’m wrong) It is for indicating that a thread of execution in .net is to be STA compatible, and not for indicating that my COM object needs to be compatible).

Here’s my declaration so far. Do you see anything that I need to add?


    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [ComDefaultInterface(typeof(ITestClass1))]
    [Guid("093A3701-2C53-4A31-97C5-0F3C205E5B4C")]
    public class Class1: ITestClass1 {..}

    [ComVisible(true)]
    [Guid("8D52F785-CDD8-4248-8AB7-97B8C19DE59B")]
    public interface ITestClass1 {..}

  • 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-15T19:53:45+00:00Added an answer on May 15, 2026 at 7:53 pm

    A COM server advertises the threading model it requires with a registry entry named ThreadingModel. Single threaded is the default if the registry key is missing or when it is set to “Apartment”.

    Regasm.exe sets this key to “Both”. Which means that your server is declared to be compatible with both STA threads and MTA threads. Somewhat in keeping with .NET code in general, it supports threading but with the requirement that you have to take care of thread-safety. Changing this is very awkward, you have to write your own registration procedure and annotate it with the [ComRegisterFunction] attribute.

    The simple approach is leave the key set to “Both” and to check the apartment state in your class constructor. Use Thread.GetCurrentThread().GetApartmentState(). If you get MTA then throw an exception to tell the client that you don’t support multi-threading. Lots of .NET classes do this.

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

Sidebar

Related Questions

I have a little Templating class, that keeps all settings inside the php class.
I have a C# class library that contains methods that need to be used
First, a little background. I have two ASP.NET web applications that use SQLServer session
I have a class that is parsing an object to be sent to a
I have little working knowledge of python. I know that there is something called
I have a class that I need to binary serialize. The class contains one
I have a generic class that I need to constrain to only value types
The problem is that I need a little extra functionality to an object of
I have created a little drawing area class and now need a pixmap to
Ok, I need a little help. I have these two PHP classes class menu

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.