locked
Help with opening settings tap OpenSettings() RRS feed

  • Question

  • Hi, I've added a button to my add-in that opens the settings tap - using this code it just locks up the console:


    MainTabUserControl.vb

        Private Sub SettingsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsButton.Click
            Me.m_consoleServices.OpenSettings(New Guid("2a3e714d-3123-44a7-8f00-727862969bc8"))
        End Sub
    
    


    HomeServerTabExtender.vb

        Public ReadOnly Property SettingsGuid() As Guid Implements IConsoleTab.SettingsGuid
            Get
                Return New Guid("2a3e714d-3123-44a7-8f00-727862969bc8")
            End Get
        End Property


    Any idea what I'm doing wrong?
    Thanks.
    Tuesday, January 26, 2010 9:53 PM

Answers

  • OK, you have a few problems:

    1. consoleServices in MainTabUserControl is private, so you can't assign anything to that value from outside the control
    2. Because MainTabUserControl.consoleServices never got assigned a value, calling OpenSettings() on it caused the NullReferenceException
    3. Even if consoleServices in MainTabUserControl was public, you were assigning the HomeServerTabExtender's consoleServices field to itself, like this:

    Me.consoleServices = consoleServices
    If MainTabUserControl.consoleServices was public, you'd actually want to do this:

    Me.m_tabControl.consoleServices = consoleServices
    I can see where you got confused; you've got lots of variables named the same, all in different places. The best solution is to not try to assign to the control's consoleServices field, but rather to use its constructor: 
    Me.m_tabControl = New MainTabUserControl(width, height, consoleServices)

    Tentacle Blog: http://www.tentaclesoftware.com/blog/
    WHS Disk Management: http://www.tentaclesoftware.com/WHSDiskManagement/
    • Proposed as answer by Sam WoodModerator Tuesday, February 2, 2010 7:15 AM
    • Marked as answer by madlan Wednesday, February 3, 2010 1:45 AM
    Tuesday, February 2, 2010 7:14 AM
    Moderator

All replies

  • Can you open the Settings dialog manually and then change to your settings tab without a lockup?

    Does the console lock up and then eventually crash? There should be something logged in the HomeServerConsole.xxx.log file in any case - what sort of exception do you see there? Anything in Event Viewer?
    Tentacle Blog: http://www.tentaclesoftware.com/blog/
    WHS Disk Management: http://www.tentaclesoftware.com/WHSDiskManagement/
    Thursday, January 28, 2010 8:08 AM
    Moderator
  • Hi Sam, I get a "System.NullReferenceException: Object reference not set to an instance of an object." error in the log, not sure exactly what this means.

    I'm using your guide and Brendans templates (great guide I must say, thanks Sam!!)


    System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.HomeServer.HomeServerConsoleTab.S.MainTabUserControl.OpenSettingsTab() in HomeServerConsoleTab.SManager.dll
       at Microsoft.HomeServer.HomeServerConsoleTab.S.MainTabUserControl.SettingsButton_Click(Object sender, EventArgs e) in HomeServerConsoleTab.SManager.dll
       at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) in System.Windows.Forms.dll
       at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e) in System.Windows.Forms.dll
       at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) in System.Windows.Forms.dll
       at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) in System.Windows.Forms.dll
       at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) in System.Windows.Forms.dll
       at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) in System.Windows.Forms.dll
       at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) in System.Windows.Forms.dll
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) in System.Windows.Forms.dll
       at System.Windows.Forms.Control.WndProc(Message& m) in System.Windows.Forms.dll
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m) in System.Windows.Forms.dll
       at System.Windows.Forms.ToolStrip.WndProc(Message& m) in System.Windows.Forms.dll
       at Microsoft.HomeServer.Controls.ConsoleToolBar.WndProc(Message& m) in HomeServerControls.dll
       at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(Message& m) in System.Windows.Forms.dll
       at System.Windows.Forms.Control+ControlNativeWindow.WndProc(Message& m) in System.Windows.Forms.dll
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) in System.Windows.Forms.dll
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) in System.Windows.Forms.dll
       at System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) in System.Windows.Forms.dll
       at System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) in System.Windows.Forms.dll
       at System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) in System.Windows.Forms.dll
       at System.Windows.Forms.Application.Run(Form mainForm) in System.Windows.Forms.dll
       at Microsoft.HomeServer.HomeServerConsole.MainForm.Main(String[] args) in HomeServerConsole.exe
    Thursday, January 28, 2010 5:13 PM
  • It sounds like m_consoleServices might still be null when you try to call OpenSettings. Are you passing through the reference to the IConsoleServices instance from your HomeServerTabExtender contructor?

    You'd need to create a property on your control to take IConsoleServices, or change the constructor of the control.

    Something like (I don't know VB.NET, so you get to read C# :) ):

     

    public HomeServerTabExtender(int width, int height, IConsoleServices consoleServices)

    {

    consoleTabControl =

    new MainTabUserControl(width, height)

    consoleTabControl.ConsoleServices = consoleServices

    }


    Tentacle Blog: http://www.tentaclesoftware.com/blog/
    WHS Disk Management: http://www.tentaclesoftware.com/WHSDiskManagement/
    Thursday, January 28, 2010 6:24 PM
    Moderator
  • Hi Sam, Everything is as defined in the template from Brendan, I thought the SettingsGuid() Propery in the HomeServerTabExtender code was ok?:




    Public ReadOnly Property SettingsGuid() As Guid Implements IConsoleTab.SettingsGuid
            Get
                Return New Guid("2a3e714d-3123-44a7-8f00-727862969bc8")
            End Get
        End Property





    My HomeServerTabExtender.vb:

    Public Class HomeServerTabExtender
        Implements IConsoleTab
    
        Private consoleServices As IConsoleServices
        Private m_tabControl As MainTabUserControl
    
        Public Sub New(ByVal width As Integer, ByVal height As Integer, ByVal consoleServices As IConsoleServices)
            Me.m_tabControl = New MainTabUserControl()
            Me.consoleServices = consoleServices
        End Sub
    
        Public ReadOnly Property SettingsGuid() As Guid Implements IConsoleTab.SettingsGuid
            Get
                Return New Guid("2a3e714d-3123-44a7-8f00-727862969bc8")
            End Get
        End Property
    
        Public ReadOnly Property TabControl() As Control Implements IConsoleTab.TabControl
            Get
                Return m_tabControl
            End Get
        End Property
    
        Public ReadOnly Property TabImage() As Bitmap Implements IConsoleTab.TabImage
            Get
                Return My.Resources.DefaultToolBarIcon
            End Get
        End Property
    
        Public ReadOnly Property TabText() As String Implements IConsoleTab.TabText
            Get
                Return "SManager"
            End Get
        End Property
    
        Public Function GetHelp() As Boolean Implements IConsoleTab.GetHelp
            Return False
        End Function
    End Class
    

    Thursday, January 28, 2010 7:18 PM
  • I'm guessing this Sub from MainTabUserControl.vb passes through the reference in the template?

        Public Sub New(ByVal width As Integer, ByVal height As Integer, ByVal consoleServices As IConsoleServices)
            Me.New()
            Me.Width = width
            Me.Height = height
            Me.m_consoleServices = consoleServices
        End Sub
    Thursday, January 28, 2010 11:32 PM
  • Ok, back to one of my original questions, then: can you go to Settings manually and change to your settings tab?

    It might be worth zipping and posting your solution somewhere (or emailing it to me - you can contact me via http://tentaclesoftware.com/blog/contact.aspx).
    Tentacle Blog: http://www.tentaclesoftware.com/blog/
    WHS Disk Management: http://www.tentaclesoftware.com/WHSDiskManagement/
    Friday, January 29, 2010 12:20 AM
    Moderator
  • Hi Sam, I've zipped up an example:

    http://drop.io/hidden/pxno6ikaddpd3r/asset/c2V0dGluZ3N0ZXN0LXppcA%253D%253D

    (VB VS2008)

    Thanks,
    Alan.
    Monday, February 1, 2010 10:55 PM
  • Hi Alan,

    Will have a look when I get home from work tonight.

    Again though, can you open Settings and change to your settings tab successfully? Also, please post the whole HomeServerConsole.xxx.log file that corresponds to the crash, there may be other relevant info in there.
    Tentacle Blog: http://www.tentaclesoftware.com/blog/
    WHS Disk Management: http://www.tentaclesoftware.com/WHSDiskManagement/
    Monday, February 1, 2010 11:10 PM
    Moderator
  • OK, you have a few problems:

    1. consoleServices in MainTabUserControl is private, so you can't assign anything to that value from outside the control
    2. Because MainTabUserControl.consoleServices never got assigned a value, calling OpenSettings() on it caused the NullReferenceException
    3. Even if consoleServices in MainTabUserControl was public, you were assigning the HomeServerTabExtender's consoleServices field to itself, like this:

    Me.consoleServices = consoleServices
    If MainTabUserControl.consoleServices was public, you'd actually want to do this:

    Me.m_tabControl.consoleServices = consoleServices
    I can see where you got confused; you've got lots of variables named the same, all in different places. The best solution is to not try to assign to the control's consoleServices field, but rather to use its constructor: 
    Me.m_tabControl = New MainTabUserControl(width, height, consoleServices)

    Tentacle Blog: http://www.tentaclesoftware.com/blog/
    WHS Disk Management: http://www.tentaclesoftware.com/WHSDiskManagement/
    • Proposed as answer by Sam WoodModerator Tuesday, February 2, 2010 7:15 AM
    • Marked as answer by madlan Wednesday, February 3, 2010 1:45 AM
    Tuesday, February 2, 2010 7:14 AM
    Moderator
  • Thanks so much for your advice Sam, its working great now!
    Wednesday, February 3, 2010 1:43 AM