locked
Error when create an Add-in in VS2010 RRS feed

  • Question

  • When I create An Add-in project (tester) . It appears 2 Addin file :

    1. tester for testing.AddIn

    2.tester.AddIn

    like this : http://preview.filesonic.com/img/353291.mini.png

    If I close the VS 2010 , it's ok . But when I reopen VS 2010 , It appears an error  : http://preview.filesonic.com/img/353281.mini.png

    then I code that Addin and build it , all succesful . Now I load this Addin in Add-in manager and get the same error : http://preview.filesonic.com/img/353281.mini.png

    any help?

    Monday, March 14, 2011 10:30 AM

Answers

  • Hello,

    Start by adding exception handlers to locate the offending line of code. See:

    HOWTO: Troubleshooting Visual Studio and Office add-ins
    http://www.mztools.com/resources_vsnet_addins.aspx

    To add commands, commandbars and buttons, see:

    HOWTO: Adding buttons, commandbars and toolbars to Visual Studio .NET from an add-in.
    (same link)

    and see also:

    HOWTO: Use correctly the OnConnection method of a Visual Studio add-in
    (same link)


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    • Proposed as answer by Victor_Chen Tuesday, March 22, 2011 9:49 AM
    • Marked as answer by Victor_Chen Wednesday, March 23, 2011 9:08 AM
    Tuesday, March 15, 2011 8:43 PM
  • You running under a debugger is the quickest way to find out what exception your code is throwing.

    Ryan

    • Proposed as answer by Victor_Chen Tuesday, March 22, 2011 9:49 AM
    • Marked as answer by Victor_Chen Wednesday, March 23, 2011 9:08 AM
    Wednesday, March 16, 2011 2:14 PM

All replies

  • The images are so small that you can't see then. Can you make it larger or post the text of the errors?
    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Tuesday, March 15, 2011 7:06 AM
  • The pics can be viewed at full size by removing the .mini part in the URL.

    The message indicates your AddIn threw an exception. The reason it is happening on re-launch of VS is likely that you  set it to load at startup, the same thing happens in the Experimental Instance because, well your AddIn is still throwing an exception. Are you trying to add an already existing command/toolbar? If you add dynamically created commands/toolbars you likely only need to do it one time (the first time the AddIn is run) not every single launch.

    Ryan

    Tuesday, March 15, 2011 3:05 PM
  • Hello,

    Start by adding exception handlers to locate the offending line of code. See:

    HOWTO: Troubleshooting Visual Studio and Office add-ins
    http://www.mztools.com/resources_vsnet_addins.aspx

    To add commands, commandbars and buttons, see:

    HOWTO: Adding buttons, commandbars and toolbars to Visual Studio .NET from an add-in.
    (same link)

    and see also:

    HOWTO: Use correctly the OnConnection method of a Visual Studio add-in
    (same link)


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    • Proposed as answer by Victor_Chen Tuesday, March 22, 2011 9:49 AM
    • Marked as answer by Victor_Chen Wednesday, March 23, 2011 9:08 AM
    Tuesday, March 15, 2011 8:43 PM
  • this is my OnConnection funtion

    public void OnConnection(
        object application, ext_ConnectMode connectMode,
        object addInInst, ref Array custom)
            {
                _applicationObject = (DTE2)application;
                _addInInstance = (AddIn)addInInst;
                if (connectMode == ext_ConnectMode.ext_cm_UISetup)
                {
                    object[] contextGUIDS = new object[] { };
                    Commands2 commands =
                     (Commands2)_applicationObject.Commands;
                    string toolsMenuName = "Tools";

                    Microsoft.VisualStudio.CommandBars.CommandBar
                        menuBarCommandBar = ((
                            Microsoft.VisualStudio.CommandBars.CommandBars)
                            _applicationObject.CommandBars)["MenuBar"];
                    CommandBarControl toolsControl =
                        menuBarCommandBar.Controls[toolsMenuName];
                    CommandBarPopup toolsPopup =
                     (CommandBarPopup)toolsControl;

                    try
                    {
                        Command command = commands.AddNamedCommand2(
                            _addInInstance, "KeystrokeFinder",
                            "KeystrokeFinder",
                            "Executes the command for KeystrokeFinder",
                            true, 59, ref contextGUIDS,
                            (int)vsCommandStatus
                                .vsCommandStatusSupported +
                            (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle
                                .vsCommandStylePictAndText,
                            vsCommandControlType
                                .vsCommandControlTypeButton);

                        if ((command != null) &&
                            (toolsPopup != null))
                        {
                            command.AddControl(
                                toolsPopup.CommandBar, 1);
                        }
                    }
                    catch (System.ArgumentException ex)
                    {
                        System.Console.WriteLine(ex);
                    }
                }
            }

    this is my QueryStatus function

    public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
            {
                if (neededText ==
        vsCommandStatusTextWanted
            .vsCommandStatusTextWantedNone)
                {
                    if (commandName ==
                        "KeystrokeFinder.Connect.KeystrokeFinder")
                    {
                        status =
                           (vsCommandStatus)
                            vsCommandStatus.vsCommandStatusSupported |
                            vsCommandStatus.vsCommandStatusEnabled;
                        return;
                    }
                }
            }

    this is my Exec function

    public void Exec(
        string commandName, vsCommandExecOption executeOption,
        ref object varIn, ref object varOut, ref bool handled)
            {
                handled = false;
                if (executeOption ==
                    vsCommandExecOption.vsCommandExecOptionDoDefault)
                {
                    if (commandName ==
                        "KeystrokeFinder.Connect.KeystrokeFinder")
                    {
                        OutputWindow outWin =
                            _applicationObject.ToolWindows.OutputWindow;
                        OutputWindowPane outPane =
                            outWin.OutputWindowPanes.Add(
                                "Keyboard Shortcuts");
                        outPane.Activate();

                        foreach (Command cmd in
                            _applicationObject.Commands)
                        {
                            object[] cmdBindings =
                                cmd.Bindings as object[];
                            if (cmdBindings.Length > 0)
                            {
                                string bindingStr =
                                    string.Join(", ", cmdBindings);
                                outPane.OutputString(
                                    "Command: " + cmd.Name +
                                    ", Shortcut: " + bindingStr +
                                    "\n");
                            }
                        }

                        handled = true;
                        return;
                    }
                }
            }

     

    this project is simply create a tool to output the list of command and its shorcut to output window . Plz help if anywhere's wrong

    Wednesday, March 16, 2011 8:15 AM
  • You running under a debugger is the quickest way to find out what exception your code is throwing.

    Ryan

    • Proposed as answer by Victor_Chen Tuesday, March 22, 2011 9:49 AM
    • Marked as answer by Victor_Chen Wednesday, March 23, 2011 9:08 AM
    Wednesday, March 16, 2011 2:14 PM