I am writing a Wcf Service library and want to load an unmanaged com dll. The com dll threaded model is not set so its a Single-threaded legacy component that runs only in the main STA threading model
In wcf service, I have set the apartment as STA like
Now when I try to create the instance of com component, it gives an exception
System.Runtime.InteropServices.SEHException : External component has thrown an exception.
When I debug the com dll and it was throwing an error RPC_E_WRONG_THREAD
.
I can fix the problem by setting threading model to Free Threaded Marshaller
. But i am not allowed to change the current threading model of com dll.
So please help me that how can I access the com dll from wcf service?
.Net Framework 4.0, Windows 7 x64
Well, finally the problem is resolved....
steps:
set the dispatcher defined in the wcf service to the current dispatcher like
WcfTest.Service1.disp = System.Windows.Threading.Dispatcher.CurrentDispatcher;
and thats all :)