Inspector.CurrentItem object reference not set to an instance

G

g62msdnatll

PLATFORM/DEVENV: VS .NET C#, Outlook 2003, Windows XP

PROBLEM: In Outlook 2003, when the user clicks on a mailto: link in a mail
message, Outlook will launch a new inspector, with the To: field filled in
with the email address of the mailto: link.

The only way I can think of to get the To: field is the get the
Inspector.CurrentItem when the New_Inspector event fires. However, using the
Inspector returned by the New_Inspector event, Inspector.CurrentItem is not
set to an instance of an object. Therefore, I can't access the To: field.

So, is there a problem, or is there another way to get to the information
I'm looking for?

Any help would be greatly appreciated.
Thanks!
 
P

Peter Huang [MSFT]

Hi

I can not reproduce the problem.
I think you may try to use VBA code for test first to see if that works for
you.
Dim o As Class2
Sub Test()
Set o = New Class2
Debug.Print "Hello"
End Sub

Public WithEvents myOlInspectors As Outlook.Inspectors

Private Sub Class_Initialize()
Set myOlInspectors = Application.Inspectors
End Sub

Private Sub myOlInspectors_NewInspector(ByVal Inspector As Inspector)
End Sub'Set break here.


Also here is my C# test code for your reference.
namespace NewInspectorAddin
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Diagnostics;
#region Read me for Add-in installation and setup information.
// When run, the Add-in wizard prepared the registry for the Add-in.
// At a later time, if the Add-in becomes unavailable for reasons such as:
// 1) You moved this project to a computer other than which is was
originally created on.
// 2) You chose 'Yes' when presented with a message asking if you wish
to remove the Add-in.
// 3) Registry corruption.
// you will need to re-register the Add-in by building the MyAddin21Setup
project
// by right clicking the project in the Solution Explorer, then choosing
install.
#endregion

/// <summary>
/// The object for implementing an Add-in.
/// </summary>
/// <seealso class='IDTExtensibility2' />
[GuidAttribute("90335B0C-26D6-452D-A657-4E19D9044F4D"),
ProgId("NewInspectorAddin.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
/// <summary>
/// Implements the constructor for the Add-in object.
/// Place your initialization code within this method.
/// </summary>
public Connect()
{
}

/// <summary>
/// Implements the OnConnection method of the IDTExtensibility2
interface.
/// Receives notification that the Add-in is being loaded.
/// </summary>
/// <param term='application'>
/// Root object of the host application.
/// </param>
/// <param term='connectMode'>
/// Describes how the Add-in is being loaded.
/// </param>
/// <param term='addInInst'>
/// Object representing this Add-in.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
Debug.WriteLine("OnConnection");
olApp = application as Outlook.Application;
Ips = olApp.Inspectors as Outlook.Inspectors;
Ips.NewInspector+=new
Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(I
nspectors_NewInspector);
}

/// <summary>
/// Implements the OnDisconnection method of the IDTExtensibility2
interface.
/// Receives notification that the Add-in is being unloaded.
/// </summary>
/// <param term='disconnectMode'>
/// Describes how the Add-in is being unloaded.
/// </param>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
if(mi !=null)
{
Marshal.ReleaseComObject(mi);
mi = null;
}
if(Ips !=null)
{
Marshal.ReleaseComObject(Ips);
Ips = null;
}
if(olApp !=null)
{
Marshal.ReleaseComObject(olApp);
olApp = null;
}

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}

/// <summary>
/// Implements the OnAddInsUpdate method of the IDTExtensibility2
interface.
/// Receives notification that the collection of Add-ins has changed.
/// </summary>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnAddInsUpdate(ref System.Array custom)
{
}

/// <summary>
/// Implements the OnStartupComplete method of the IDTExtensibility2
interface.
/// Receives notification that the host application has completed
loading.
/// </summary>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnStartupComplete(ref System.Array custom)
{
}

/// <summary>
/// Implements the OnBeginShutdown method of the IDTExtensibility2
interface.
/// Receives notification that the host application is being
unloaded.
/// </summary>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnBeginShutdown(ref System.Array custom)
{
}
private Outlook.Application olApp=null;
private Outlook.Inspectors Ips = null;
private Outlook.MailItem mi=null;
private void
Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector
Inspector)
{
mi = Inspector.CurrentItem as Outlook.MailItem;
if(mi ==null)
Debug.WriteLine("MailItem is null");
else
{
Debug.WriteLine(mi.To);
}
}
}
}



Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

g62msdnatll

Thank you for your help. You are right, the CurrentItem is not null, it was
some other mailitem property that was giving me that error.

I have a followup question:

When the user clicks on a mailto: link, the mailitem.To field is non-null.
When the user clicks on reply to a mail, the mailitem.To field seems to be
null.

why?
 
P

Peter Huang [MSFT]

Hi

Based on my test, it is strange that I can not reproduce the problem.
If we open a mailitem, the DebugView Monitor will output the fields in the
To.
If I click the Reply, a new mail item will be opened, and the field to will
be output too.

Would you please try my test code one more time to see if the problem
persists.
Or
I think you may try to run the Addin on another machine to try to isolate
the problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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