System.MissingMethodException: Method not found

Unanswered System.MissingMethodException: Method not found

  • Dienstag, 19. Oktober 2010 14:43
     
     

    Hello I get the follwing error.

     

    System.MissingMethodException: Method not found: 'Microsoft.Office.Core.CommandBars Microsoft.Office.Interop.Excel._Application.get_CommandBars()'.

       at Jedox.Palo.XlAddin.Connect.NotInEditMode()

       at Jedox.Palo.XlAddin.Connect.mItemPasteView_Click(CommandBarButton Ctrl, Boolean& CancelDefault)

     

    with

            public static bool NotInEditMode()
            {
                bool FileOpenEnabled = false;
                CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
                CultureInfo originalUICulture = Thread.CurrentThread.CurrentUICulture;

                try
                {
                    // set current thread's culture to en-US
                    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

                    FileOpenEnabled = (bool)ExcelHelper.oExcelApp.CommandBars.FindControl(Type.Missing, 23, Type.Missing, Type.Missing).Enabled;
                }
                catch (Exception ex)
                {
                    ErrorHandler.DisplayError("Error in NotInEditMode !", ex);
                }
                finally
                {

                    Thread.CurrentThread.CurrentCulture = originalCulture;
                    Thread.CurrentThread.CurrentCulture = originalUICulture;
                }


                return FileOpenEnabled;
            }

    where

    ExcelHelper.oExcelApp is defined as

    public static Excel.Application

    with

    using Excel = Microsoft.Office.Interop.Excel;

     

    This happens with Click to Run Office 2010 after exchanging the XP PIAs by the 2003 PIAs.

    Strange is that the exception isn't caught in NotInEditMode although there is a catch, but by the caller of NotInEditMode.

    Changing back to XP PIA isn't really a solution, since the 2003 PIA's solved a lot of problems for us.

    Has Anybody an idea ?

     

     

     

     

     

    • Verschoben Bessie ZhaoModerator Freitag, 22. Oktober 2010 07:57 for better support (From:Visual Studio Tools for Office)
    •  

Alle Antworten

  • Dienstag, 19. Oktober 2010 16:09
     
     

    First thing, if Office 2010 is installed then you should be using the Office 2010 PIAs, it shouldn't be working at all with the PIAs of another version.

    Beyond that, there are issues with using Click-to-run versions of Office 2010 with any other code, as they run in a virtual environment, rather than in your actual machine's environment.

    But until you have the right set of PIAs, all other discussion points are moot...


    Cindy Meister, VSTO/Word MVP
  • Mittwoch, 20. Oktober 2010 14:44
     
     

    I have replaced 2003 PIAs by 2010 PIAs.

    No change.

     

    We use the enabled status of the File Open Menuitem just to decide whether Excel is in Editmode.

    If there's an easier way I would be glad to hear it and we can workaround this problem.

     

    best regards

      Hendrik Schmieder

     

     

  • Mittwoch, 20. Oktober 2010 15:21
     
     

    Hi Hendrik

    OK, first off, it would probably be better to have this in the Excel.Developer forum, as this is an issue with Excel, not with VSTO. I can move the message there, if you wish.

    But continuing with the troubleshooting:

    1. The next thing I'd try is whether the command still works at all in VBA. Possibly, it's no longer avaiable in Excel 2010, what with the change to the Ribbon. I made a quick test, and it appears to still be valid - on my installation. However...

    2. Updates to Office have been known to "break" things. I remember it happening once with commandbars back in version 2003 (or 2002). So it's important you test, as well, to make sure.

    3. The other question is, whether this is a problem specifically with the Click-to-run version of Office 2010. If you have a parallel installation of Excel 2010, test whether your code works in that case.

     


    Cindy Meister, VSTO/Word MVP
  • Donnerstag, 21. Oktober 2010 13:07
     
     

    Hello Cindy,

    the strange thing is that this C# code works with Excel 2000, Excel 2003, Excel 2007 and normal Excel 2010.

    It even works in a VM with Win7 64 and Click To run Excel 2010 (maybe because another Excel was installed in this VM).

    It is one ClickToRun installation where it doesn't work (unfortunatly this installation belongs to one of our Vize presidents).

     

    It is ok for me if you move this topic.

     

    with best regards

      Hendrik

     

     

     

  • Dienstag, 26. Oktober 2010 14:25
     
     

    OK,

    now a coworker has now installed ClickToRun Excel 2010 and VS 2010.

    Unfortunatly the debugger doesn't break.

    and the file

    excel.exe.config

    with content

    <?xml version="1.0"?>
    <configuration>
       <startup>
         <supportedRuntime version="v2.0.50727"/>
       </startup>
    </configuration>

    doesn't help for breaking.

  • Donnerstag, 28. Oktober 2010 09:26
     
     

    OK,

    found a way to debug.

    After starting ClickToRun Excel attach debugger to a process called 'excel.exe'.

     

    This is the code we tried to debug, beginning with  mItemPasteView_Click.

    ExcelHelper.oExcelApp is definded as Excel.Application.

    <C# code>

    public static bool NotInEditMode()
    {
        bool FileOpenEnabled = true;

            if (!GeneralConst.isClickToRun())
            {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
                    CultureInfo originalUICulture = Thread.CurrentThread.CurrentUICulture;

                    try
                    {
                        // set current thread's culture to en-US
                        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
                        FileOpenEnabled = (bool)ExcelHelper.oExcelApp.CommandBars.FindControl(Type.Missing, 23, Type.Missing, Type.Missing).Enabled;
                    }
                    catch (Exception ex)
                    {
                        ErrorHandler.DisplayError("Error in NotInEditMode !", ex);
                    }
                    finally
                    {

                        Thread.CurrentThread.CurrentCulture = originalCulture;
                        Thread.CurrentThread.CurrentCulture = originalUICulture;
                    }
        }

        return FileOpenEnabled;
    }


    private void mItemPasteView_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
    {
        Excel.XlCalculation oldcalculation = Excel.XlCalculation.xlCalculationManual;

            try
            {
            this.thisThread.CurrentCulture = new CultureInfo("en-US");
                    this.thisThread.CurrentUICulture = new CultureInfo("en-US");

                    if (!NotInEditMode())
                    {
                        return;
                    }
            // more code
        }
        catch (Exception e)
            {
            ErrorHandler.DisplayError("Error Initialising Paste View Form Window.", e);
            }
    }

    </C# code>

     

    Whenthe debugger stops at line

                    if (!NotInEditMode())

    and we try to step into NotInEditMode() an exception is thrown :

    System.MissingMethodException: Method not found: 'Microsoft.Office.Core.CommandBars Microsoft.Office.Interop.Excel._Application.get_CommandBars()'.

       at Jedox.Palo.XlAddin.Connect.NotInEditMode()

       at Jedox.Palo.XlAddin.Connect.mItemPasteView_Click(CommandBarButton Ctrl, Boolean& CancelDefault)

    Why can't we step into NotInEditMode() ?

    BTW:

    VS 2010 using .Net 2.0 on 64bit Windows 7.