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

R

Russ Green

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/default.asp?url=/library/en-us/dnout2k2/html/odc_oladdinvbnet.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
 
C

Chris

Russ said:
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/default.asp?url=/library/en-us/dnout2k2/html/odc_oladdinvbnet.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?
 
R

Russ Green

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top