Hi,
I'm writing a WPF application that calls code in an AddIn which is effectively
public Splash GetAboutDialog(){
return new Splash();
}
class Splash: Window
{ .... }
I use MethodInvoke to call via RunCommand( "GetAboutDialog" )
internal bool RunCommand(string macroName)
{
IExtendedEntryPoint entryPoint = this.macroAddIn as IExtendedEntryPoint;
if (entryPoint == null)
return false;
object obj = entryPoint.GetEntryPointObject();
Type t = obj.GetType();
try
{
t.InvokeMember(macroName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, obj, null);
return true;
}
....
}
Now this code works perfectly when not in Debug mode, but once in the debugger, it will fail with the following:
The calling thread must be STA, because many UI components require this.
Delving further, the thread calling GetAboutDialog is indeed MTA when in the debugger, but presumably not when the code is called normally. I presume that AddInProcess that is hosting the addin in the debugger is starting the thread the MTA apartment model. What can I do to resolve this?
Many thanks,
Alec