By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,209 Members | 1,834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,209 IT Pros & Developers. It's quick & easy.

Troubleshooting "Object reference not set to an instance of an object." Managed Exception. How?

P: n/a
I am completely baffled when the following managed exception is thrown:
"Object reference not set to an instance of an object" from a nested
subroutine when referencing a variable allocated on the program stack.

Given the following simple example:

void T( System::String * S )
{
const wchar_t __pin * pchars PtrToStringChars( S ) ;

size_t n = S->Length ; // Exception appears to be thrown here,
why???

// More stuff ....

}

void V( void )
{
System::String * str = S"this_is_a_string" ;

T( str ) ;
}

The exception appears to be thrown at the line 'size_t n = S->Length ;' in
T(), which frankly seems rather bizarre. Worse, the exception occurs on
fairly infrequent occassions in an (multi-threaded) application, and it is
not readily reproducable.

I need some suggestions on how to go about troubleshooting this problem.

Are there still open issues with garbage collection in a VC.NET 2003 app
using the 1.1.4322 framework?

If not, how can a variable be destroyed before all references to it are
deleted?

--
================================================== ====================
================================================== ====================
==
== Bob Riedel
== Beckman Coulter, Incorporated
== PO Box 8000 W-529
== 200 S Kraemer Blvd
== Brea CA 92822-8000
==
== Email 1: ra******@beckman.com
== Email 2: ra******@mindspring.com
==
==
== The opinions expressed are my own, and do not necessarily represent
== those of Beckman Coulter, Inc.
==
================================================== ====================
================================================== ====================
==
== "Effective education is the key to successful democracy."
==
== "Criticizing the actions of others offers so little risk, and
== requires so little effort that it is, without exception, the tool
== of the lazy and of the foolish -- who have neither the intelligence
== to discover, nor the discipline to pursue, a realistic
== alternative."
==
================================================== ====================
================================================== ====================
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I am withdrawing this question. It appears that my simplification of the
problem was a little too simple, and I left out the step that was the cause
of the problem. The exception, from what I can tell, is being thrown
correctly.

"Robert A Riedel" <ra**********@beckman.com> wrote in message
news:u6*************@TK2MSFTNGP11.phx.gbl...
I am completely baffled when the following managed exception is thrown:
"Object reference not set to an instance of an object" from a nested
subroutine when referencing a variable allocated on the program stack.

Given the following simple example:

void T( System::String * S )
{
const wchar_t __pin * pchars PtrToStringChars( S ) ;

size_t n = S->Length ; // Exception appears to be thrown here,
why???

// More stuff ....

}

void V( void )
{
System::String * str = S"this_is_a_string" ;

T( str ) ;
}

The exception appears to be thrown at the line 'size_t n = S->Length ;' in
T(), which frankly seems rather bizarre. Worse, the exception occurs on
fairly infrequent occassions in an (multi-threaded) application, and it is
not readily reproducable.

I need some suggestions on how to go about troubleshooting this problem.

Are there still open issues with garbage collection in a VC.NET 2003 app
using the 1.1.4322 framework?

If not, how can a variable be destroyed before all references to it are
deleted?

--
================================================== ====================
================================================== ====================
==
== Bob Riedel
== Beckman Coulter, Incorporated
== PO Box 8000 W-529
== 200 S Kraemer Blvd
== Brea CA 92822-8000
==
== Email 1: ra******@beckman.com
== Email 2: ra******@mindspring.com
==
==
== The opinions expressed are my own, and do not necessarily represent
== those of Beckman Coulter, Inc.
==
================================================== ====================
================================================== ====================
==
== "Effective education is the key to successful democracy."
==
== "Criticizing the actions of others offers so little risk, and
== requires so little effort that it is, without exception, the tool
== of the lazy and of the foolish -- who have neither the intelligence
== to discover, nor the discipline to pursue, a realistic
== alternative."
==
================================================== ====================
================================================== ====================

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.