473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I get rid of "Object reference not set to an instance of an object"?

Hello guys,

I have hit a dead end in trying to solve this problem. The thing is, I can't run the the program here because it has to run on a server which is in another place. All I receive here is a logfile with exceptions that happens when they test the program on the server.

I'm using VS2005, VB.NET, XP Pro, CDO 1.21 dll
Anyway, this function Logs on and traverses through "Public Folders" until it finds a folder I'm looking for.

I hope someone could help me cause I need to resolve this fast.

Here is the source code:

Expand|Select|Wrap|Line Numbers
  1. Public Sub Logon(ByVal profile As String, ByVal RootFolder As String)
  2.  
  3.         m_Session = New MAPI.Session
  4.         m_Session.Logon(profile, , False, , , , )
  5.  
  6.         ' Go the fax store
  7.         Dim Folders As String() = RootFolder.Split("/".ToCharArray())
  8.  
  9.         Dim i As Integer
  10.         Dim objInfoStores As Object
  11.         Dim objPublicFolderRoot As Object
  12.         Dim objParent As Object
  13.         Dim Parent As MAPI.Folder
  14.  
  15.         objInfoStores = m_Session.InfoStores
  16.         m_InfoStores = DirectCast(objInfoStores, MAPI.InfoStores)
  17.  
  18.         For i = 1 To CInt(m_InfoStores.Count)
  19.             Dim InfoStoreName As String
  20.             objPublicFolderRoot = m_InfoStores.Item(i)
  21.             InfoStoreName = m_InfoStores.Item(i).ToString
  22.             If InfoStoreName = Folders(0) Then
  23.                 m_PublicFolderRoot = DirectCast(objPublicFolderRoot, MAPI.InfoStore)
  24.                 Exit For
  25.             End If
  26.         Next
  27.  
  28.         objParent = m_PublicFolderRoot.RootFolder
  29.         Parent = DirectCast(objParent, MAPI.Folder)
  30.  
  31.         For i = 1 To Folders.Length - 1
  32.             Parent = GetFolderByName(Folders(i), Parent)
  33.         Next
  34.         m_FaxRoot = Parent
  35.  
  36.     End Sub
  37.  
and this is the code for the GetFolderByName Function

Expand|Select|Wrap|Line Numbers
  1. Friend Function GetFolderByName(ByVal folderName As String, Optional ByVal parent As MAPI.Folder = Nothing) As MAPI.Folder
  2.         Dim CdoSession As MAPI.Session = m_Session
  3.         Dim CdoInfoStores As MAPI.InfoStores
  4.         Dim CdoInfoStore As MAPI.InfoStore
  5.         Dim CdoFolderRoot As MAPI.Folder
  6.         Dim CdoFolders As MAPI.Folders
  7.         Dim CdoFolder As MAPI.Folder
  8.         Dim bFound As Boolean
  9.  
  10.         Dim i As Integer = 1
  11.         Dim objInfoStores As Object
  12.         Dim objInfoStore As Object
  13.         Dim objFolderRoot As Object
  14.         Dim objFolders As Object
  15.         Dim objParentFolders As Object
  16.         Dim objFolder As Object
  17.  
  18.         If parent Is Nothing Then
  19.             objInfoStores = CdoSession.InfoStores
  20.             CdoInfoStores = DirectCast(objInfoStores, MAPI.InfoStores)
  21.             objInfoStore = CdoInfoStores.Item("Public Folders")
  22.             CdoInfoStore = DirectCast(objInfoStore, MAPI.InfoStore)
  23.  
  24.             For i = 1 To CInt(CdoInfoStores.Count)
  25.                 Dim InfoStoreName As String
  26.                 objInfoStore = CdoInfoStores.Item(i)
  27.                 InfoStoreName = CdoInfoStores.Item(i).ToString
  28.                 If InfoStoreName = "Public Folders" Then
  29.                     CdoInfoStore = DirectCast(objInfoStore, MAPI.InfoStore)
  30.                     Exit For
  31.                 End If
  32.             Next
  33.  
  34.             objFolderRoot = CdoInfoStore.RootFolder
  35.             CdoFolderRoot = DirectCast(objFolderRoot, MAPI.Folder)
  36.             objFolders = CdoFolderRoot.Folders
  37.  
  38.             CdoFolders = DirectCast(objFolders, MAPI.Folders)
  39.         Else
  40.             ' Get the Folders collection from the parent folder.
  41.             objParentFolders = parent.Folders
  42.             CdoFolders = DirectCast(objParentFolders, MAPI.Folders)
  43.         End If
  44.  
  45.         ' Loop through the folders in the collection until the
  46.         ' desired folder is found.
  47.         bFound = False
  48.         objFolder = CdoFolders.GetFirst
  49.         CdoFolder = DirectCast(objFolder, MAPI.Folder)
  50.         Do While (Not bFound) And Not (CdoFolder Is Nothing)
  51.             If CdoFolder.Name.ToString = folderName Then
  52.                 bFound = True
  53.             Else
  54.                 objFolder = CdoFolders.GetNext
  55.                 CdoFolder = DirectCast(objFolder, MAPI.Folder)
  56.             End If
  57.  
  58.         Loop
  59.  
  60.         GetFolderByName = CdoFolder
  61.  
  62.         ' Release our local objects.
  63.         CdoFolder = Nothing
  64.         CdoFolders = Nothing
  65.         CdoFolderRoot = Nothing
  66.         CdoInfoStore = Nothing
  67.         CdoInfoStores = Nothing
  68. End Function ' GetFolderByName
  69.  
Please help,
JAN
Sep 18 '08 #1
3 1625
MrMancunian
569 Expert 512MB
Hi Jan,

As I see the topicname, the first thing I think is: "He forgot to use 'New'". This goes for new objects instances. Try using

Expand|Select|Wrap|Line Numbers
  1. Dim .... as New Object
Now, as I don't know exactly what exceptions you get it's hard to tell where you should and shouldn't use them, but at least this is a start. You can try posting the list of exceptions...
Sep 18 '08 #2
Hi! Thanks for the reply

This is the only exception i got from the testers

Object reference not set to an instance of an object.
at CDOMessaging.ExchangeConnector.Logon(String profile, String RootFolder)
at InFaxAlert.InFaxAlert.OnWakeup2(Object sender, ElapsedEventArgs e)

I'll try placing "New" in my Object declarations
Like this right?
Expand|Select|Wrap|Line Numbers
  1. Dim objInfoStores As New Object
  2.  
Thanks,
JAN
Sep 18 '08 #3
MrMancunian
569 Expert 512MB
Hi! Thanks for the reply

This is the only exception i got from the testers

Object reference not set to an instance of an object.
at CDOMessaging.ExchangeConnector.Logon(String profile, String RootFolder)
at InFaxAlert.InFaxAlert.OnWakeup2(Object sender, ElapsedEventArgs e)

I'll try placing "New" in my Object declarations
Like this right?
Expand|Select|Wrap|Line Numbers
  1. Dim objInfoStores As New Object
  2.  
Thanks,
JAN
It's easier to test it instead of asking me if it looks right ;-) It does look right, but I'm not sure whether or not it will work...
Sep 18 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bob Cannistraci | last post by:
A three-tier user authentication system was running without a problem for almost a year and now is suddenly dysfunctional. We don't know of any changes to any of the servers. It's quite maddening....
22
by: Dr Duck | last post by:
GDay all, Something seems odd to me.... I wrote a simple C# function public void bind(ref object a, ref object b, bool atob) { if(atob) b = a; else
1
by: Chris Magoun | last post by:
I suddenly received an unexpected error in my project. I have been working on this project for some time without this issue. Nothing has changed in the form that caused the exception. A little...
18
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12,...
1
by: Gummy | last post by:
Hello, I've been banging my head against the wall for a few days on this. When I run a page, either in "View in Browser" or I actually build the solution, I occasionally and very randomly get...
2
by: louie.hutzel | last post by:
This JUST started happening, I don't remember changing any code: When I click the submit button on my form, stuff is supposed to happen (which it does correctly) and a result message is posted back...
35
by: Chris | last post by:
Hi, I tried to create a class which must change the propety 'visible' of a <linktag in the masterpage into 'false' when the user is logged. But i get the error: "Object reference not set to an...
0
by: Tamer Ibrahim | last post by:
Hi, Sometimes, I got the following error message when I use ajax calendar control on some aspx pages : Object reference not set to an instance of an object. Description: An unhandled exception...
4
by: My Pet Programmer | last post by:
Ok guys, I'm really looking for someone to tell me how bad a hack this is, and if I'm close to where I should be with it. The basic situation is that I have a class which creates a basic...
2
by: snester | last post by:
Hi, I am using visual studio 2005 and recently created a new web service project. I seem to have edited the global config file (inadvertently) somewhere along the line. All new projects I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.