David Ghikas

Hi,

We have developed a VSTO Outlook application that allows a User to process an email by selecting it and clicking on a custom button on the main tool bar.

The program works at our company but our client encounters the exception Object reference not set to an instance of an object when they try and process an email in their sent folder (they can process emails in other folders). We are unable to reproduce the exception at our company.

Does anybody have any ideas

Thanks in advance,

Dave



Re: Visual Studio Tools for Office Error encountered while trying to process an email in the sent mail folder.

DaveRogers

I'm having a similar problem, I get this error trying to process Inbox items, but only on certain computers at our company! Anyone got any ideas



Re: Visual Studio Tools for Office Error encountered while trying to process an email in the sent mail folder.

HawVer

You trying to read something that doesn't exist. For example if you have a loop wich reads the subjects from emails then the subject should not be null. If it is, the .net framewok will raise an exception like that. You could solve the problem like the following example.

if (sentMail.Subject != null)
{
processmail();
}




Re: Visual Studio Tools for Office Error encountered while trying to process an email in the sent mail folder.

Sue Mosher - Outlook MVP

Just to add to HawVer's good advice: Posting a code snippet that shows what your application is doing is pretty essential to getting feedback on your code. Not the whole application, just the relevant bits.

Also keep in mind that any Outlook folder may contain items of different classes. You cannot assume that they are all MailItem objects. The Class property will tell you for certain.





Re: Visual Studio Tools for Office Error encountered while trying to process an email in the sent mail folder.

David Ghikas

Sue,< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

My apologies for the lack of code. 

I have a button on the Outlook main toolbar that runs the following code when clicked:

private void ForwardToCyberGrantsButtonClick( Office.CommandBarButton ctrl , ref bool cancel )

{

      if ( this.ActiveExplorer().Selection.Count == 0 )

      {

            LoggingPkg.LogMessage( userIdString , passwordString , LoggingPkg.MessageTypes.Warning ,

            "Select a mail message to forward and then click the Forward Email to CyberGrants button." );

            return;

      }

      if ( this.ActiveExplorer().Selection.Count > 1 )

      {

            LoggingPkg.LogMessage( userIdString , passwordString , LoggingPkg.MessageTypes.Warning ,

            "You can only forward one email at a time to CyberGrants." );

            return;

      }

      Object selectedObject = this.ActiveExplorer().Selection[ 1 ];

      if ( selectedObject is Outlook.MailItem )

      {

            Outlook.MailItem mailItem = ( selectedObject as Outlook.MailItem );

            string SenderEmailString = mailItem.SenderEmailAddress.ToString(); // Null Exception occurs here

            ( other code runs here )

      }

}

 

The above code works fine at both our development site and our client site.  The problem occurs at our client site when the mail item is from the sent folder.  Referencing the same object at our development location does not produce the error.

 

The only difference that I can see between our client site and our development site is that our development site uses POP/SMTP while our client site uses Microsoft Exchange Server 2003 Serivce Pack 2.  Could this account for the difference





Re: Visual Studio Tools for Office Error encountered while trying to process an email in the sent mail folder.

Sue Mosher - Outlook MVP

Nothing jumps out at me. For what you're doing, Outlook shouldn't behave differently on an Exchange store vs. a .pst file store. Is there a possibility that the client is configured in such a way that they have only headers for messages in the Sent Items folder It would be an unusual configuration.

I would strongly recommend that, if you're going to develop for a client with Exchange, you need to test on Exchange. At the very least, get a mailbox or two from a hosted Exchange provider.





Re: Visual Studio Tools for Office Error encountered while trying to process an email in the sent mail folder.

David Ghikas

Thanks Sue,

Getting a mailbox from a hosted Exchange provider for testing purposes makes a lot of sence.

Dave