By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,032 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,032 IT Pros & Developers. It's quick & easy.

Object ref not set to instance of an object...

P: n/a
I'm trying to build a simple COM addin for Outlook using VB.NET 2003. I've
downloaded this example as a start point...

http://msdn.microsoft.com/library/de...addinvbnet.asp

But the onConnect method fails with Object reference to set to an
instance...bla bla bla.

Here is the code from the method as it exists in my addin (pretty much the
same as the example)

'Extensibility.IDTExtensibility2 Event Stubs
Public Sub OnConnection(ByVal application As Object, ByVal
connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object,
ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnConnection
Dim oApp As Outlook.Application
Dim oType As Type
Dim GetProgID As Object
Dim MyProgID As String
Dim oArgs As Object()
'Dim Reg As RegistryKey
'Dim WriteDiagnostics As Integer
'Dim strKey As String
Try
MsgBox("Mail manager conencted", MsgBoxStyle.Information)

'Use InvokeMember to get ProgID of addInInst object
oType = addInInst.GetType
GetProgID = oType.InvokeMember("ProgID", _
BindingFlags.Public Or BindingFlags.GetField Or
BindingFlags.GetProperty, _
Nothing, _
addInInst, _
oArgs)
MyProgID = CType(GetProgID, String)

'Convert application from generic object to
Outlook.Application
oApp = CType(application, Outlook.Application)

'Don't call InitHandler if Explorers.Count = 0 and
Inspectors.Count = 0
If oApp.Explorers.Count = 0 And oApp.Inspectors.Count = 0
Then
Exit Sub
End If

'Evaluate ConnectMode
Select Case connectMode
Case ext_ConnectMode.ext_cm_AfterStartup
Case ext_ConnectMode.ext_cm_CommandLine
Case ext_ConnectMode.ext_cm_External
Case ext_ConnectMode.ext_cm_Solution
Case ext_ConnectMode.ext_cm_Startup
Case ext_ConnectMode.ext_cm_UISetup
End Select

' Initialize COMAddin object with this connect object to
allow
' external clients to get access to exposed features
oApp.COMAddIns.Item(MyProgID.ToString).Object = Me

'Call InitHandler
m_BaseClass.InitHandler(oApp, MyProgID)
Catch ex As SystemException
MsgBox(ex.Message & " : " & ex.Message,
MsgBoxStyle.Critical, "Mail Manager")
End Try
End Sub
Feb 12 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Russ Green wrote:
I'm trying to build a simple COM addin for Outlook using VB.NET 2003. I've
downloaded this example as a start point...

http://msdn.microsoft.com/library/de...addinvbnet.asp

But the onConnect method fails with Object reference to set to an
instance...bla bla bla.

Here is the code from the method as it exists in my addin (pretty much the
same as the example)

'Extensibility.IDTExtensibility2 Event Stubs
Public Sub OnConnection(ByVal application As Object, ByVal
connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object,
ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnConnection
Dim oApp As Outlook.Application
Dim oType As Type
Dim GetProgID As Object
Dim MyProgID As String
Dim oArgs As Object()
'Dim Reg As RegistryKey
'Dim WriteDiagnostics As Integer
'Dim strKey As String
Try
MsgBox("Mail manager conencted", MsgBoxStyle.Information)

'Use InvokeMember to get ProgID of addInInst object
oType = addInInst.GetType
GetProgID = oType.InvokeMember("ProgID", _
BindingFlags.Public Or BindingFlags.GetField Or
BindingFlags.GetProperty, _
Nothing, _
addInInst, _
oArgs)
MyProgID = CType(GetProgID, String)

'Convert application from generic object to
Outlook.Application
oApp = CType(application, Outlook.Application)

'Don't call InitHandler if Explorers.Count = 0 and
Inspectors.Count = 0
If oApp.Explorers.Count = 0 And oApp.Inspectors.Count = 0
Then
Exit Sub
End If

'Evaluate ConnectMode
Select Case connectMode
Case ext_ConnectMode.ext_cm_AfterStartup
Case ext_ConnectMode.ext_cm_CommandLine
Case ext_ConnectMode.ext_cm_External
Case ext_ConnectMode.ext_cm_Solution
Case ext_ConnectMode.ext_cm_Startup
Case ext_ConnectMode.ext_cm_UISetup
End Select

' Initialize COMAddin object with this connect object to
allow
' external clients to get access to exposed features
oApp.COMAddIns.Item(MyProgID.ToString).Object = Me

'Call InitHandler
m_BaseClass.InitHandler(oApp, MyProgID)
Catch ex As SystemException
MsgBox(ex.Message & " : " & ex.Message,
MsgBoxStyle.Critical, "Mail Manager")
End Try
End Sub


What line is causing the error?
Feb 12 '06 #2

P: n/a
Well I posted the question as I didn't know how to debug a COM addin from
VS.NET but I've since discovered the trick and found and fixed the problem.

Thanks for replying though
Feb 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.