ControlCouldNotBeInitializedException cannot be caught in Word? RRS feed

  • Question

  • hi,

    does anyone know if we can get ControlCouldNotBeInitializedException in VSTO word project? I Created Word and Excel document vsto projects in VS2010. and then Paste code         Dim a As Boolean
                Dim invalidControl As System.Windows.Forms.Control
                Me.Controls.AddControl(invalidControl, 50, 50, 50, 50, "badControl")
            Catch uniEx As ControlCouldNotBeInitializedException
                a = True
            Catch ex1 As Exception
                a = False
            End Try  this exception is caught in Excel project, but not caught in Word project, anyone knows this? Is this a bug?

    Wednesday, December 28, 2011 11:14 AM


  • Yes, I can. I created a Word 2010 Document project, pasted the code to ThisDocument_Startup, the exception is thrown as expected. Print the variable value on status bar, you can see it's thrown, but was handled.

    Catch uniEx As ControlCouldNotBeInitializedException
                a = True
                Globals.ThisDocument.Application.StatusBar = a.ToString()

    In Excel 2010 Workbook project, it throws ArgumentNullException.


    1. Excel, Controls.AddControl(...)

    Forrest Guo | MSDN Community Support | Feedback to us

    Saturday, December 31, 2011 3:56 AM