Monday, July 18, 2005 9:55 PMI'm running into a different problem as well here. I'm getting this error message when I attempt to trigger a custom menu item added by a VSIP Package using the DTE automation.
I have a regular winforms application that launches an instance of Visual Studio and gets the DTE object that it exposes through OLE Automation. I have a VSIP Package registered that is essentially a slightly modified ToolWindow that adds a menu to the View menu. I've noticed that the VSIP Package doesnt load up until the menu item is clicked, so as a quick work around, I want to trigger that window just to force the VSIP Package to load up. I'm doing that with DTE.ExecuteCommand("View.MyToolWindowVB").
When this is called, an exception is thrown indicating that the call was rejected. I can manually select that menu item no problem, and I can trigger other menu items (ie "File.NewProject") without problems. Any ideas why I cant trigger this menu item?
The full exception text is below.
System.Runtime.InteropServices.COMException was unhandled
Message="Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))"
at EnvDTE._DTE.ExecuteCommand(String CommandName, String CommandArgs)
at automationtest.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\administrator.jnetd\my documents\visual studio 2005\Projects\automationtest\automationtest\Form1.vb:line 58
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String commandLine)
at automationtest.My.MyApplication.Main(String Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 77
at System.AppDomain.nExecuteAssembly(Assembly assembly, String args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String args)
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
Wednesday, July 20, 2005 9:03 PMHi Bill,
Thanks for the question.
The problem you are encountering is the result of a timing issue. The IDE take a while to start up and be ready to process commands. It looks to me that you are hitting the case where automation methods aren't really ready to be called because the IDE is not really fully started.
One way around this problem is to pause your application to let VS get fully started and be idle. A better way to accomplish this is to call WaitForInputIdle, but this would require some interop with windows APIs if you are writing in managed code.
In general if you get that return value it means that the callee is busy and you should retry after some period of time.
I hope this helps to get you unblocked.
Wednesday, July 20, 2005 10:36 PMThanks Allen. I tried this theory by dropping a sleep(10000) in there and you are exactly right. VS evidently just needed a little time to start up something.
Thursday, January 18, 2007 10:01 AM
Specifically put in the timeout may not be optimum solution. What if the application is running at the much slower PC that needs the sleep time to be longer?
My feeling is that, you should change the whole situation using a synchronous call (Utilizing ASynchronousCallBack but indefinitely waiting until the process is done) to block all the subsequent statements until the IDE is completely loaded.
delegate <return type> StartIDEDelegate(<any parameters needed to start the IDE>);
StartIDEDelegate showIDE = new StartIDEDelegate(<the function that starts the IDE>);
IAsyncResult iAsyncResult = showIDE.BeginInvoke(<any parameters needed to start the IDE>, null, null);
<return type> callResult = showIDE.EndInvoke(iAsyncResult);
In this way, you don't have to worry whether you're over-waiting (sleep too long) or under-waiting (sleep too short)
Monday, January 29, 2007 5:36 PMhi,
im running the same issue here.
i need to instantiate visual studio and create a solution so i can add some projects.
Kam's solution is the right one but i cant still do it...
if im in debug mode it works always but while running sometimes i get the exception...
Kam do i need to create the solution inside the delegate or just the visual studio instance?
Friday, February 02, 2007 9:21 AMI do bump into this issue occasionally, but come to think of it, there are still some works have to be done.
First, Open an IDE will need a bit of time to be fully loaded, opening a solution or adding projects do need some additional time.
Hence, beside synchronizing the IDE "Launching" time, you will need to ensure that it synchronizes the time for each project to be added or for each solution to be opened.
Hope this helps.
Friday, February 16, 2007 7:00 PMAakham thanks for your reply!
in my case i dont even open solutions. i only add projects (but im not syncronizing it).
i'll give it a try.
but there is a question that bothers me. i've created handlers for the DTEEvents, for instance, the OnStartupComplete and it is not raised!!!! i cant get it to go to the handler...
Any idea why?
Friday, February 23, 2007 7:20 AMI don't quite sure why the event handlers are not fired. Hence I will just share some of my past experience here.
Note: I assumed you have registered the event handlers to the intended events in the correct manner.
1. Are you running the IDE in a separate thread and you invoke the event handlers in your UI Control class?
2. Is there any exception prior to the event handler invocation or during the event handler's invocation.
These questions are important.
If the first question is "yes" and if you didn't have this control block for the thread to be parented, you might running into an exception which later on the IDE silents it.
<Return Value> Method()
return (<ReturnValue>)this.Invoke(new <Some Other Delegate>(this.Method));
// Whatever it intended to do.
If the first question is no, please look at any possibility that an exception is thrown right at the beginning of event handler.
Hopes this help.
Friday, February 23, 2007 3:30 PM
I think Even If you dont create the solution, It would create the one By Default. You may not save it.
Well, When you create the project, by AddTemplate.....it returns you project. Try Catching that object, even if you choose not to use it.
Also, You will not face this problem if you are using a High end machine. The Solution of pausing for some time is correct
Monday, February 26, 2007 11:47 AM@aahkam
Hi, thanks for your reply!
im registering the event as follows:
private DTE2 StartIDEMethod()
DTE2 dte = (DTE2) System.Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.DTE.8.0"));
dte.Events.DTEEvents.OnStartupComplete += new _dispDTEEvents_OnStartupCompleteEventHandler(DTEEvents_OnStartupComplete);
throw new Exception("The method or operation is not implemented.");
As for running the IDE i did as you suggested:
created a delegate
use the IAsyncResult for waiting indefinetely untill de BeginInvoke method ends (starting the IDE...)
// the StartIDEMethod in the StartIDEDelegate constructor is shown above
StartIDEDelegate startIDE = new StartIDEDelegate(StartIDEMethod);
IAsyncResult iAsyncResult = startIDE.BeginInvoke(null, null);
for creating the solution and add two different kind of projects i used the same process...
in the end i close the application and release dte
So, yes i am running the IDE in a separate thread and i invoke the event handlers in the ui control class. I mean, the assync mode is achieved by a new thread right?
Now im not getting the solution you provided.
Is Method() the method used for running the IDE as well?
Thanks for your reply!
its true it does create a default solution, but if you dont save or build it (create the .sln) you will only get a directory with your projects folder and not a .sln to open all of them.
Wednesday, February 28, 2007 1:16 AM
Thanks for the feedback.
What I'm trying to say is that, you may need to include the control block for thread to be parented like below. And please avoid the throw statement (last line) in the function. Any exception that happens in the events in your application which is external to the DTE will be silented automatically to avoid application crashes.
delegate void ParamlessVoidMethodDelegate();
throw new Exception("The method or operation is not implemented.");
Wednesday, February 28, 2007 9:11 AMthank you for the reply.
i see what you mean by now.
its very frustrating because in debug mode it goes just fine and i can create the solutions and add the projects just fine...
but still even in debug mode the onStartupCompleteEvent is never raised, at least to me...
im catching the correct event right!? (dte.Events.DTEEvents.OnStartupComplete)
anyway i was using this event just in the case the other solution didnt work (the async calls)
just to be sure that from that point the IDE has been started and could begin adding projects and stuff. I tried in several machines and it did just the same...
Wednesday, February 28, 2007 5:18 PM
Finally I think I got the Answer. Please see the link.
MIcrosoft has give a Solution with this problem with Some Introp.
They have this class and You need to instantate this, Once you are Done Just Revoke the Stuff.
Excellent Perf. Good Stuff............I got my Problem Solved on a slower machine as well.
Thursday, March 01, 2007 9:40 AM@Amol wankhede
Thank you so much for the precious link!!! It was very helpfull. It realy solved the bastard!!
Thanks to you too! You have kept my flame on fire... : )
Thanks to you both
Wednesday, January 16, 2008 11:39 AM
I am encountering this problem only in a specific environment and not in others. (the environment in which my code fails, raising the above exception, is faster than the other environments i have tested my code in)
To give you a brief description of the problem,
There is a service we have created which executes once every 24 hrs, which spawns another thread.
This thread opens instances of Word Documents to create files.
Now, at this stage,it is raising the exception "Call was rejected by callee"
Could you kindly shed some light on this?
Is there any other way of circumventing this than by directly or indirectly introducing a lag between the call and the processing?
Also, if i were to introduce sleep, will the sleeptime impact functioning of my code in different environments?
Tuesday, April 15, 2008 12:40 AM
Thank you Amol, this link is exactly what I have been searching for. The title and text on the link page do not contain the error messages for the problem it solves, so I was unable to find it from searching.
Thank you Thank you for posting this link!
Thursday, September 29, 2011 2:07 PMThanks a lot. It is working perfect now.