I have to include a .NET application into another .NET application as a plugin. The plugin interface requires me to inherit from a template form. The form is then attached in a MDI when the plugin is loaded.
Everything is working so far, but whenever I register for drag and drop events, set the autocomplete mode for a combobox or at various other situations I get the following exception:
...the current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it...
The main application is running in MTA and developed by another company, so there is nothing I can do about it.
I tried to do the things that cause these exceptions in STA threads, but that didn't solve the problem either.
Has anyone been in the same situation? Is there anything I can do to solve the problem?
You could try to spawn new thread and call CoInitialize with 0 on it (aparment threaded) and run your application in this thread. However you won't be to update controls directly within this thread you should use Control.Invoke for every UI modification.
I don't know if this is going to work for sure, but you could try it.