I have a C# program that uses a C++ WinRT DLL. The C# program creates an instance of a public WinRT class Foo which internally tries to instantiate an object of a second WinRT class Bar that isn’t declared public. When calling “ref new” on the Bar class, it throws an exception saying “Activating a single-threaded class from MTA is not supported”.
How do I configure the Bar class to that it works in a MTA-style threaded application? Is it a per-class or DLL-wide setting?
It’s per-class behavior, controlled by attributes
ThreadingModelandMarshallingBehavior. See MSDN for details – Threading and Marshaling.Usage is like this: