NullReferenceException: Only on IIS Server. Only Some times. I feellike an idiot.

J

jehugaleahsa

Here is some ASP.NET C# code that does NOT work when ran on the
servers:

public Decimal CustomerKey
{
get { return get<Decimal>
(dataTable.DataTable.FK_CUSTOMERColumn); }
set
{
set(dataTable.DataTable.FK_CUSTOMERColumn, value);
}
}

For some reason, I get a NullReferenceException when the setter is
called. Now, I feel like an idiot because usually
NullReferenceExceptions are due to my own stupidity. I'm not saying
that's not the case here. Okay, but here is the weird thing... this
only happens on the server, and if I change the setter to this:

string message = String.Empty;
try
{
message += dataTable.ToString();
message += dataTable.DataTable.ToString();
message +=
dataTable.DataTable.FK_CUSTOMERColumn.ToString();
set(dataTable.DataTable.FK_CUSTOMERColumn, value);
}
catch (Exception exception)
{
while (exception != null)
{
message += exception.Message +
exception.StackTrace;
exception = exception.InnerException;
}
throw new Exception(message);
}

It will suddenly start working on the server! My guess was that
perhaps the dataTable was null, the internal DataTable was null or
that the column was null. Nope; they're all initialized! I even
checked inside the set method to see if it was the cause of the issue.
But depending on the code I write, the exception is thrown somewhere
different. I even had an exception occur on this line:

if (value == null)

where value is an object. How can that happen? @#$%^!

So, what would make my code blow up on a seemingly random line of
code? Some things allow to code work. Some things make it blow up on a
different line. It is almost like the library is being corrupted or
something.

I tried going line by line adding in exceptions deeper and deeper into
the code until they stopped. But that was like hitting a moving
target. Stranger, this same code has been working in production for
months and months. It also works on my development machine. I'm so
confused.

I think for now I am going to do a check sum on my DLLs to make sure
they are identical on my machine and on the server. I am running out
of ideas... and sanity.
 
J

jehugaleahsa

Here is some ASP.NET C# code that does NOT work when ran on the
servers:

        public Decimal CustomerKey
        {
            get { return get<Decimal>
(dataTable.DataTable.FK_CUSTOMERColumn); }
            set
            {
                    set(dataTable.DataTable.FK_CUSTOMERColumn, value);
            }
        }

For some reason, I get a NullReferenceException when the setter is
called. Now, I feel like an idiot because usually
NullReferenceExceptions are due to my own stupidity. I'm not saying
that's not the case here. Okay, but here is the weird thing... this
only happens on the server, and if I change the setter to this:

                string message = String.Empty;
                try
                {
                    message += dataTable.ToString();
                    message += dataTable.DataTable.ToString();
                    message +=
dataTable.DataTable.FK_CUSTOMERColumn.ToString();
                    set(dataTable.DataTable.FK_CUSTOMERColumn, value);
                }
                catch (Exception exception)
                {
                    while (exception != null)
                    {
                        message += exception.Message +
exception.StackTrace;
                        exception = exception.InnerException;
                    }
                    throw new Exception(message);
                }

It will suddenly start working on the server! My guess was that
perhaps the dataTable was null, the internal DataTable was null or
that the column was null. Nope; they're all initialized! I even
checked inside the set method to see if it was the cause of the issue.
But depending on the code I write, the exception is thrown somewhere
different. I even had an exception occur on this line:

    if (value == null)

where value is an object. How can that happen? @#$%^!

So, what would make my code blow up on a seemingly random line of
code? Some things allow to code work. Some things make it blow up on a
different line. It is almost like the library is being corrupted or
something.

I tried going line by line adding in exceptions deeper and deeper into
the code until they stopped. But that was like hitting a moving
target. Stranger, this same code has been working in production for
months and months. It also works on my development machine. I'm so
confused.

I think for now I am going to do a check sum on my DLLs to make sure
they are identical on my machine and on the server. I am running out
of ideas... and sanity.

Well, this time I completely deleted every record off of the server
and published using Front Page extensions (I don't know why we do it
that way). And now it works. I checked my DLLs and they were identical
across my machines. Perhaps one of those libraries that IIS generates
was causing me an issue. I am going to see if I can reproduce the
error. I'd like to know what's causing it, since I know it won't be
the last time.
 
J

jehugaleahsa

Here is some ASP.NET C# code that does NOT work when ran on the
servers:

        public Decimal CustomerKey
        {
            get { return get<Decimal>
(dataTable.DataTable.FK_CUSTOMERColumn); }
            set
            {
                    set(dataTable.DataTable.FK_CUSTOMERColumn, value);
            }
        }

For some reason, I get a NullReferenceException when the setter is
called. Now, I feel like an idiot because usually
NullReferenceExceptions are due to my own stupidity. I'm not saying
that's not the case here. Okay, but here is the weird thing... this
only happens on the server, and if I change the setter to this:

                string message = String.Empty;
                try
                {
                    message += dataTable.ToString();
                    message += dataTable.DataTable.ToString();
                    message +=
dataTable.DataTable.FK_CUSTOMERColumn.ToString();
                    set(dataTable.DataTable.FK_CUSTOMERColumn, value);
                }
                catch (Exception exception)
                {
                    while (exception != null)
                    {
                        message += exception.Message +
exception.StackTrace;
                        exception = exception.InnerException;
                    }
                    throw new Exception(message);
                }

It will suddenly start working on the server! My guess was that
perhaps the dataTable was null, the internal DataTable was null or
that the column was null. Nope; they're all initialized! I even
checked inside the set method to see if it was the cause of the issue.
But depending on the code I write, the exception is thrown somewhere
different. I even had an exception occur on this line:

    if (value == null)

where value is an object. How can that happen? @#$%^!

So, what would make my code blow up on a seemingly random line of
code? Some things allow to code work. Some things make it blow up on a
different line. It is almost like the library is being corrupted or
something.

I tried going line by line adding in exceptions deeper and deeper into
the code until they stopped. But that was like hitting a moving
target. Stranger, this same code has been working in production for
months and months. It also works on my development machine. I'm so
confused.

I think for now I am going to do a check sum on my DLLs to make sure
they are identical on my machine and on the server. I am running out
of ideas... and sanity.

Well, this time I completely deleted every record off of the server
and published using Front Page extensions (I don't know why we do it
that way). And now it works. I checked my DLLs and they were identical
across my machines. Perhaps one of those libraries that IIS generates
was causing me an issue. I am going to see if I can reproduce the
error. I'd like to know what's causing it, since I know it won't be
the last time.
 
P

Paul

What is the set method calling

public Decimal CustomerKey
{
get { return get<Decimal>
(dataTable.DataTable.FK_CUSTOMERColumn); }
set
{
***** set(dataTable.DataTable.FK_CUSTOMERColumn, value);
***** where is this method
}
}
 
P

Paul

What is the set method calling

public Decimal CustomerKey
{
get { return get<Decimal>
(dataTable.DataTable.FK_CUSTOMERColumn); }
set
{
***** set(dataTable.DataTable.FK_CUSTOMERColumn, value);
***** where is this method
}
}
 
J

jehugaleahsa

What is the set method calling

        public Decimal CustomerKey
        {
            get { return get<Decimal>
(dataTable.DataTable.FK_CUSTOMERColumn); }
            set
            {
                 *****   set(dataTable.DataTable.FK_CUSTOMERColumn, value);
***** where is this method
            }
        }















- Show quoted text -

This error was actually do to something being cached in the _V tables
created by IIS. We deleted these out and everything started to work
fine. The code wasn't responsible. The set method looked something
like this:

void set(string columnName, object value)
{
// When it was the following line that last executed,
// I knew something fishy was going on. There is no way
// this line could cause an exception.
if (value == null)
{
dataRow[columnName] = DBNull.Value;
}
else
{
dataRow[columnName] = value;
}
}
 
J

jehugaleahsa

What is the set method calling

        public Decimal CustomerKey
        {
            get { return get<Decimal>
(dataTable.DataTable.FK_CUSTOMERColumn); }
            set
            {
                 *****   set(dataTable.DataTable.FK_CUSTOMERColumn, value);
***** where is this method
            }
        }















- Show quoted text -

This error was actually do to something being cached in the _V tables
created by IIS. We deleted these out and everything started to work
fine. The code wasn't responsible. The set method looked something
like this:

void set(string columnName, object value)
{
// When it was the following line that last executed,
// I knew something fishy was going on. There is no way
// this line could cause an exception.
if (value == null)
{
dataRow[columnName] = DBNull.Value;
}
else
{
dataRow[columnName] = value;
}
}
 

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