getting System.ExecutionEngineException error when i tried to run Add in to access Outlook using c#

Hi,

i got the error 'System.ExecutionEngineException' when i debug the Add in to access Outlook by using interop assembly. can any body help me how to resolve the problem.

when iam tring to add a button to Outlook toolbar it is giving the error

example:

this.toolbarButton = (CommandBarButton)commandBars["Standard"].Controls["Attachment"];

thanks

Sivaji



Answer this question

getting System.ExecutionEngineException error when i tried to run Add in to access Outlook using c#

  • stewed

    Hello Sivaji Srinivas Narra,

    there are different approaches to handle this.

    One is to assign your button a unique Tag and use the CommandBar.FindControl method.

    You could also wrap that function with a try catch statement

    Personally I prefer to loop over the CommandBar.Controls collection and see ih there is a Control with that name.

    Here is an example (but with a toolbar, but it's just the same)

    /// Since the CommandBars not always get cleaned, first try to get our commandbar

    /// We could do this with a try / catch, but I always try to avoid exceptions

    /// so loop over the Explorer.Commandbars and have a look for _ CommandBar

    foreach ( Office.CommandBar bar in _Explorer.CommandBars )

    {

    // test for our Name

    if (bar.Name == "X4UTools")

    {

    // o.k. we got it - atomic waste...

    bar.Delete ();

    break;

    }

    }

    // Start with a fresh one...

    _CommandBar = _Explorer.CommandBars.Add("X4UTools", _Missing, 0, 1);

    taken from my sample X4U Tools

    Hope this helps,

    greets, Helmut
    [http://www.x4u.de]



  • Job Lot

    hi,

    thanks for giving me the response.

    actually iam creating one button name 'Attachment'in outlook by using addin.after that iam going to find the created button from control bar at that time it is giving the error.

    example:

    try

    {

    // See if it already exists

    this.toolbarButton = (CommandBarButton)commandBars["Standard"].Controls["Attachment"];

    }

    catch(Exception)

    {

    // Create it

    this.toolbarButton = (CommandBarButton)commandBars["Standard"].Controls.Add(1, System.Reflection.Missing.Value, System.Reflection.Missing.Value,System.Reflection.Missing.Value, System.Reflection.Missing.Value);

    this.toolbarButton.Caption = "Attachment";

    this.toolbarButton.Style = MsoButtonStyle.msoButtonCaption;

    }

    after this while shutting down outlook iam going to find the button by using this

    this.toolbarButton = (CommandBarButton)commandBars["Standard"].Controls["Attachment"];

    this time it is giving error

    can you please give me some suggetions about this

    thanks

    Sivaji


  • apan

    Hi,

    The code by Helmut may have solved your issue. I am still interested in investigating why you were getting a System.ExecutionEngine exception.

    I tried your code in the Application Startup and Shutdown event handlers and I didn't see the exception. Could you describe what event handler you were adding the button and what event handler you get the exception in Also could you try it in the simplest version of your addin where you can reproduce the exception and describe what you are doing

    Thanks



  • Michael Kochetkov

    System.ExecutionEngine exception means the runtime perform an illegal operation. You should normally not be getting this exception.

    I tried the line of code you have above and got an ArgumentException because the Standard toolbar does not seem to contain a control called "Attachment".

    Are you consistently getting this exception Can you provide a little more detail on where exactly the exception It would be helpful if you pasted a couple of lines of code around where the exception is thrown.

    Thanks



  • getting System.ExecutionEngineException error when i tried to run Add in to access Outlook using c#