Error running app but not while debugging!

D

Don Gollahon

Help please! .NET 2.0.

I have a hashtable defined:

public static Hashtable Params;

It currently is in a shared class in my app. I have moved it from the
main form to the shared class but get the same results no matter what.

When I run the app within VS it works fine! But when I run it outside
of VS I get "object reference is not set to an instance of an object"
and it is the Params.

Any ideas how this could be?
 
J

José Joye

Could you give more explanation about it.

For instance, how do you intialize the Params member.
At what line of code do you get the error (you can get it by looking at the
stack trace of the error object.

- José
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

could you post some code?
Also take a look in the deail of the exception , as the line # of where the
error occurred.
 
D

Don Gollahon

Ignacio said:
Hi,

could you post some code?
Also take a look in the deail of the exception , as the line # of
where the error occurred.

I inserted a test line to make sure this is where the problem was and
it is. The following is in the Main() method:

Main.GetINISettings();
try
{
string vstr = SharedClass.Params["LOGSERVER"].ToString();
}
catch (Exception E1)
{
MessageBox.Show("Main Params: " + E1.Message);
throw (new Exception(E1.Message));
}


And here is the GetINISettings method:

private void GetINISettings()
{
if (System.IO.File.Exists(IniName))
{
FileStream vini = new FileStream(IniName, FileMode.Open);
StreamReader vsr = new StreamReader(vini);
String[] elements;
try
{
while (!vsr.EndOfStream)
{
string vstr = vsr.ReadLine();
elements = vstr.Split('=');
SharedClass.Params.Add(elements[0], elements[1]);
}
}
catch (Exception Ex)
{
vsr.Close();
vini.Close();
Environment.ExitCode = 9000;
throw (new Exception("Config file not found or invalid: " +
Ex.Message));
//MessageBox.Show("Config file not found or invalid. " +
Ex.Message, "Error", MessageBoxButtons.OK);
return;
};
if (vsr != null)
vsr.Close();
if (vini != null)
vini.Close();
}
}
 
D

Don Gollahon

Ignacio said:
Hi,

could you post some code?
Also take a look in the deail of the exception , as the line # of
where the error occurred.

I forgot to include this in the sample I sent. It is before the other
code in Main():

SharedClass.Params = new Hashtable();
 
D

Don Gollahon

Ignacio said:
Hi,

could you post some code?
Also take a look in the deail of the exception , as the line # of
where the error occurred.

Uhhh, nevermind.

I forgot to move the ini file to the working directory.

Good grief!
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Take a look at the ini file, must probably you are using a different version
when you are debugging

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Don Gollahon said:
Ignacio said:
Hi,

could you post some code?
Also take a look in the deail of the exception , as the line # of
where the error occurred.

I inserted a test line to make sure this is where the problem was and
it is. The following is in the Main() method:

Main.GetINISettings();
try
{
string vstr = SharedClass.Params["LOGSERVER"].ToString();
}
catch (Exception E1)
{
MessageBox.Show("Main Params: " + E1.Message);
throw (new Exception(E1.Message));
}


And here is the GetINISettings method:

private void GetINISettings()
{
if (System.IO.File.Exists(IniName))
{
FileStream vini = new FileStream(IniName, FileMode.Open);
StreamReader vsr = new StreamReader(vini);
String[] elements;
try
{
while (!vsr.EndOfStream)
{
string vstr = vsr.ReadLine();
elements = vstr.Split('=');
SharedClass.Params.Add(elements[0], elements[1]);
}
}
catch (Exception Ex)
{
vsr.Close();
vini.Close();
Environment.ExitCode = 9000;
throw (new Exception("Config file not found or invalid: " +
Ex.Message));
//MessageBox.Show("Config file not found or invalid. " +
Ex.Message, "Error", MessageBoxButtons.OK);
return;
};
if (vsr != null)
vsr.Close();
if (vini != null)
vini.Close();
}
}
 
D

Don Gollahon

Ignacio said:
Hi,

Take a look at the ini file, must probably you are using a different
version when you are debugging

Yep. Actually, blush, I forgot to copy it to the working directory and
not just the development area.
 

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