A
andyblum
Hi all,
I know this message usually relates to trying to use a NULL instance of
an object. However, this is not the case in my code.
DestinationDirectory is a seperate class defined as follows:
Namespace WebLogFileMover
{
class DestinationDirectory
{
string path;
string deleteCriteria;
string type;
public DestinationDirectory()
{
path = "";
deleteCriteria = "";
type = "";
}
public string Path
{
get { return path; }
set { path = value; }
}
public string Type
{
get { return type; }
set { type = value; }
}
public string DeleteCriteria
{
get { return deleteCriteria; }
set { deleteCriteria = value; }
}
}
}
As you can see from the code below I am defining an array of this
class:
namespace WebLogFileMover
{
class ConfigurationInfo
{
ArrayList sourcePaths;
DestinationDirectory[] destinationDirectories;
DateTime lastAccessDate;
XmlDOMReader reader;
EventLogHandler el;
public ConfigurationInfo(string theFile)
{
try
{
reader = new XmlDOMReader(theFile);
el = new EventLogHandler();
PopulateSourcePaths();
PopulateLastAccessDate();
PopulateDestinationDirectories();
}
catch (Exception e)
{
el.WriteEvent("WLFM", "Unable to construct
ConfigurationClass. " + e.Message);
}
}
private void PopulateSourcePaths()
{
sourcePaths = reader.readXMLDOM("FileDir", "path");
}
private void PopulateDestinationDirectories()
{
ArrayList path;
ArrayList type;
ArrayList deleteCriteria;
path = reader.readXMLDOM("DirLocation", "path");
type = reader.readXMLDOM("DirLocation", "type");
deleteCriteria = reader.readXMLDOM("DirLocation",
"DeleteCriteria");
for (int i = 0; i <= (path.Count - 1);i++ )
{
destinationDirectories = new DestinationDirectory();
destinationDirectories.Path = path.ToString();
destinationDirectories.Type = type.ToString();
destinationDirectories.DeleteCriteria =
deleteCriteria.ToString();
i++;
}
}
private void PopulateLastAccessDate()
{
ArrayList a;
a = reader.readXMLDOM("AppData", "LastAccess");
lastAccessDate =
System.Convert.ToDateTime(a[0].ToString());
}
}
}
When I call the method PopulateDestinationDirectories() I am looping
through and instantiating a new instance:
for (int i = 0; i <= (path.Count - 1);i++ )
{
destinationDirectories = new DestinationDirectory();
destinationDirectories.Path = path.ToString();
destinationDirectories.Type = type.ToString();
destinationDirectories.DeleteCriteria =
deleteCriteria.ToString();
i++;
}
Yet, even so I am still getting the Object Reference Not set... error
message. When I debug it actually goes through the constructor and then
returns the message. Any suggestons would be appreaciated????
I know this message usually relates to trying to use a NULL instance of
an object. However, this is not the case in my code.
DestinationDirectory is a seperate class defined as follows:
Namespace WebLogFileMover
{
class DestinationDirectory
{
string path;
string deleteCriteria;
string type;
public DestinationDirectory()
{
path = "";
deleteCriteria = "";
type = "";
}
public string Path
{
get { return path; }
set { path = value; }
}
public string Type
{
get { return type; }
set { type = value; }
}
public string DeleteCriteria
{
get { return deleteCriteria; }
set { deleteCriteria = value; }
}
}
}
As you can see from the code below I am defining an array of this
class:
namespace WebLogFileMover
{
class ConfigurationInfo
{
ArrayList sourcePaths;
DestinationDirectory[] destinationDirectories;
DateTime lastAccessDate;
XmlDOMReader reader;
EventLogHandler el;
public ConfigurationInfo(string theFile)
{
try
{
reader = new XmlDOMReader(theFile);
el = new EventLogHandler();
PopulateSourcePaths();
PopulateLastAccessDate();
PopulateDestinationDirectories();
}
catch (Exception e)
{
el.WriteEvent("WLFM", "Unable to construct
ConfigurationClass. " + e.Message);
}
}
private void PopulateSourcePaths()
{
sourcePaths = reader.readXMLDOM("FileDir", "path");
}
private void PopulateDestinationDirectories()
{
ArrayList path;
ArrayList type;
ArrayList deleteCriteria;
path = reader.readXMLDOM("DirLocation", "path");
type = reader.readXMLDOM("DirLocation", "type");
deleteCriteria = reader.readXMLDOM("DirLocation",
"DeleteCriteria");
for (int i = 0; i <= (path.Count - 1);i++ )
{
destinationDirectories = new DestinationDirectory();
destinationDirectories.Path = path.ToString();
destinationDirectories.Type = type.ToString();
destinationDirectories.DeleteCriteria =
deleteCriteria.ToString();
i++;
}
}
private void PopulateLastAccessDate()
{
ArrayList a;
a = reader.readXMLDOM("AppData", "LastAccess");
lastAccessDate =
System.Convert.ToDateTime(a[0].ToString());
}
}
}
When I call the method PopulateDestinationDirectories() I am looping
through and instantiating a new instance:
for (int i = 0; i <= (path.Count - 1);i++ )
{
destinationDirectories = new DestinationDirectory();
destinationDirectories.Path = path.ToString();
destinationDirectories.Type = type.ToString();
destinationDirectories.DeleteCriteria =
deleteCriteria.ToString();
i++;
}
Yet, even so I am still getting the Object Reference Not set... error
message. When I debug it actually goes through the constructor and then
returns the message. Any suggestons would be appreaciated????