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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:47:04+00:00 2026-06-07T19:47:04+00:00

I’m having the problem described in this question: Unable to cast COM object of

  • 0

I’m having the problem described in this question:
Unable to cast COM object of type exception which manifests as the error:

Unable to cast COM object of type ‘System.__ComObject’ to interface
type ‘IMyInterface’. This operation failed because the QueryInterface
call on the COM component for the interface with IID ‘{GUID}’ failed
due to the follow error: No such interface supported

My WPF app is calling a .NET library that eventually calls a COM object. This works fine, but it runs on the main thread and blocks the UI. When I spawn a new thread and call the library from it, I’m getting that error. None of those solutions on the other question are working for me. I’m trying to understand how the runtime can have the type information loaded, but not share it between threads.

I understand that WPF apps are STA, and I know that means that any objects moving between threads will be COM marshalled. I don’t understand how the type information to say “This is a COM object, and its GUID is this” can be in the AppDomain, but inaccessible to the second thread.

Where does loaded type information live? Is it in the AppDomain, or per thread? In any case, how can I make the threads share type information? How can I fix this?

I’ve read this:
http://www.codeproject.com/Articles/9190/Understanding-The-COM-Single-Threaded-Apartment-Pa
and this:
http://msdn.microsoft.com/en-us/library/ms973913.aspx#rfacomwalk_topic10
and a bunch of other stuff that talks about COM interop, but hasn’t helped me fix it.

As per Hans Passant’s answer, I’m creating my library object inside the second STA thread:

        var thread = new Thread(delegate()
        {
            var aeroServer = new AeroServerWrapper(Config.ConnectionString);
            var ct = new CancellationToken();
            aeroServer._server.MessageReceived += ServerMessageReceived;
            aeroServer.Go(@"M:\IT\Public\TestData\file.dat", ct);
        });
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();

I understand that I might need to call Application.Run() to start the message queue if events fail to fire but I’m not getting that far: it crashes as soon as it attempts to create the COM object. The AeroServerWrapper is in a separate DLL, which calls a second DLL, which finally attempts to instantiate the COM object.

Any hints or articles would be greatly appreciated. I’d like to solve this as it is: my Plan B is to wrap the library in a console app, spawn the console app from the UI, and get status messages from it through a named pipe. That’ll work, but it seems ugly.

  • 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-07T19:47:06+00:00Added an answer on June 7, 2026 at 7:47 pm

    This goes wrong because you are calling the COM interface method from another thread. COM ensures that COM classes that declare themselves to be not thread-safe are called in a thread-safe way. The ThreadModel key in the registry specifies this, a very common value is “Apartment” (or is missing), indicating that the class is not thread-safe.

    So if you call the interface method from another thread then COM steps in and marshals the call to the thread on which the object was created, thus ensuring thread-safety. A pretty nice feature, entirely missing from .NET classes. However, COM needs help when it marshals the interface method arguments. Required because the call is made on another thread and the method call argument values need to be copied. Reflection is not a COM feature. The first thing it does is look in the registry, the HKCR\Interface\{guid} key for the ProxyStubClsid key, the guid of a helper class that knows how to serialize the arguments.

    Clearly that key is missing on your machine. Next thing it does is ask the COM object for the IMarshal interface. Clearly your COM server doesn’t implement it. And that produces the E_NOINTERFACE error. Producing good error messages has never been COM’s strength.

    Well, the writing is on the wall. The COM class you are using is not thread-safe and is missing all the plumbing required to make calling it thread-safe. It is normally pretty easy to provide the proxy/stub but the author of the component didn’t bother, not entirely uncommon. Not that it would help if he did, that plumbing ensures the method runs on the UI thread, surely what you were trying to avoid in the first place.

    The only reasonable thing you can do is create your own thread, call its SetApartmentState() method to switch to STA and create the object on that thread so the class is used in a thread-safe manner. No concurrency, but at least it is concurrent with the rest of your code. That thread must typically also pump a message loop, Application.Run(), you might get away with not pumping. You’ll know you need to pump when you see deadlock or events don’t get fired. You can find example code in this post.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build

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.