COM interop object throws InvalidCastException in one project but not in other

后端 未结 2 1322
一生所求
一生所求 2021-01-07 02:11

I have a COM object I imported in my test C# solution. Everything works fine and continues to do so.

Then I imported the same COM object in my actual solution and as

2条回答
  •  温柔的废话
    2021-01-07 02:56

    The difference was in threading. The winform thread executed the code from the main thread, whereas the asp.net didn't. It was solved by explicitly running the COM in a STAThread.

提交回复
热议问题