none
Unable to access underlying Visual C# AddIn Object. RRS feed

  • Question

  • Hi,

    I am trying to access the underlying object for my Visual C# Addin and keep running into a System Interop exception.
    Here is the code I am using:

    private void button1_Click(object sender, RoutedEventArgs e)
     {
                EnvDTE80.DTE2 myDTE2;
                myDTE2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.9.0");

                AddIns addIns = myDTE2.AddIns;
                object qee = new object();

                foreach ( AddIn myAddin in addIns)
                {
                    if (myAddin.Name.Contains("TestAddin"))
                    {
                        qee = myAddin;
                    }
                        
                }
                
               MessageBox.Show( ((AddIn)qee).Object.ToString() );
      }



    I get the exception on the MessageBox.Show call. What is the recommended way to access the AddIn.Object object? Is there anything special I need to do in my Connect.cs class?

    Thanks,

    George.
    Wednesday, December 17, 2008 1:47 AM

Answers

  • >>Is there anything special I need to do in my Connect.cs class?

    Typically, you would save a reference to the AddIn object in OnConnection().

    private AddIn _addInInstance;  
    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)  
    {  
        _addInInstance = (AddIn) addInInst;  
    Wednesday, December 17, 2008 12:19 PM

All replies

  • Read Sticky: How to ask questions to increase your chances of an answer first and try to post enough information to reproduce and troubleshoot this issue.

    Thanks.

    Return to the source, learn the way!
    Wednesday, December 17, 2008 3:50 AM
  • >>Is there anything special I need to do in my Connect.cs class?

    Typically, you would save a reference to the AddIn object in OnConnection().

    private AddIn _addInInstance;  
    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)  
    {  
        _addInInstance = (AddIn) addInInst;  
    Wednesday, December 17, 2008 12:19 PM