I just got the strangest error. I have exception code that catches a
null reference exception:
catch (NullReferenceE xception ex) { ... }
The handling code does nothing but print out data from within the
object, ex. So, nothing is changed. And I've found that the
exception object, ex, ITSELF is null!
So, by accessing it to print its innards, it throws another
NullReferenceEx ception (which is, of course, unhandled)! Printing
ex.Message actually works, it reports "Object reference not set to an
instance of an object." But, accessing ex.InnerExcepti on is what
throws the null reference, since ex is null.
Strange. I'll see if I can replicate this, and nail it down.
Zytan 7 1975
Strange. I'll see if I can replicate this, and nail it down.
I think the null reference was from ex.InnerExcepti on being null. And
I was trying to print ex.InnerExcepti on.Message. However, what threw
me off was that viewing ex in the debugger shows:
ex {"Object reference not set to an instance of an object."}
System.NullRefe renceException
This made me believe ex was null. (Of course, it would show "null" if
it was null.) But, if the object referenece in not set to an instance
of an object, then WTH is it set to? In the debugger, under ex, it
shows no methods, just "base". Under that, "base" again. Finally,
under that, it shows some methods.
Zytan
But, if the object referenece in not set to an instance
of an object, then WTH is it set to?
LOL! It's telling me that the exception IS that an object was
referenced that was null (not set to an instance of an object).
Zytan
"Zytan" <zy**********@y ahoo.comwrote in message
news:11******** *************@y 66g2000hsf.goog legroups.com...
>Strange. I'll see if I can replicate this, and nail it down.
I think the null reference was from ex.InnerExcepti on being null. And
I was trying to print ex.InnerExcepti on.Message. However, what threw
me off was that viewing ex in the debugger shows:
ex {"Object reference not set to an instance of an object."}
System.NullRefe renceException
This made me believe ex was null. (Of course, it would show "null" if
it was null.) But, if the object referenece in not set to an instance
of an object, then WTH is it set to? In the debugger, under ex, it
shows no methods, just "base". Under that, "base" again. Finally,
under that, it shows some methods.
The debugger shows ex.ToString(), which shows you ex.Message. ex is indeed
an instance of NullReferenceEx ception, with InnerException= null and
Message="Object reference not set to an instance of an object."
>
Zytan
"Zytan" <zy**********@y ahoo.comwrote in message
news:11******** *************@d 57g2000hsg.goog legroups.com...
>I just got the strangest error. I have exception code that catches a
null reference exception:
catch (NullReferenceE xception ex) { ... }
The handling code does nothing but print out data from within the
object, ex. So, nothing is changed. And I've found that the
exception object, ex, ITSELF is null!
So, by accessing it to print its innards, it throws another
NullReferenceEx ception (which is, of course, unhandled)! Printing
ex.Message actually works, it reports "Object reference not set to an
instance of an object." But, accessing ex.InnerExcepti on is what
throws the null reference, since ex is null.
Strange. I'll see if I can replicate this, and nail it down.
ex isn't null, InnerException is.
The debugger shows ex.ToString(), which shows you ex.Message. ex is indeed
an instance of NullReferenceEx ception, with InnerException= null and
Message="Object reference not set to an instance of an object."
Yup, thanks Ben, I figured it out somewhat myself. But, yeah, it's
nice to know that ToString() returns Message.
Zytan
So, by accessing it to print its innards, it throws another
NullReferenceEx ception (which is, of course, unhandled)! Printing
ex.Message actually works, it reports "Object reference not set to an
instance of an object." But, accessing ex.InnerExcepti on is what
throws the null reference, since ex is null.
ex isn't null, InnerException is.
Indeed.
Zytan
"Zytan" <zy**********@y ahoo.comwrote in message
news:11******** *************@n 76g2000hsh.goog legroups.com...
>The debugger shows ex.ToString(), which shows you ex.Message. ex is indeed an instance of NullReferenceEx ception, with InnerException= null and Message="Objec t reference not set to an instance of an object."
Yup, thanks Ben, I figured it out somewhat myself. But, yeah, it's
nice to know that ToString() returns Message.
Peeking at mscorlib with the insanely useful .NET Reflector
( http://www.aisto.com/roeder/dotnet/), we can see exactly how
Exception.ToStr ing() works:
public override string ToString()
{
string text2;
string message = this.Message;
if (this._classNam e == null)
{
this._className = this.GetClassNa me();
}
if ((message == null) || (message.Length <= 0))
{
text2 = this._className ;
}
else
{
text2 = this._className + ": " + message;
}
if (this._innerExc eption != null)
{
text2 = text2 + " ---" + this._innerExce ption.ToString( ) +
Environment.New Line + " " +
Environment.Get ResourceString( "Exception_EndO fInnerException Stack");
}
if (this.StackTrac e != null)
{
text2 = text2 + Environment.New Line + this.StackTrace ;
}
return text2;
}
>
Zytan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: TT (Tom Tempelaere) |
last post by:
Hi,
Once in a while my application throws an NullReferenceException at startup,
however it appears to be occurring in an unknown module. If I debug it and
ask to 'break', then there is no source code available (I am running in Debug
mode of course).
What could be the cause of this? Can someone shed some light on this matter?
Kind...
|
by: Matthias Kwiedor |
last post by:
Hi!
I want to create a WebBrowser Control at runtime. So i ported the "at
start creation" of the Control to a new routine.
Everything works fine, but i implement the BeforeNavigateFix and a own
Content Menu. For this i need this lines:
public void create_new_browser()
|
by: Eduard Ralph |
last post by:
Hi,
I have a weird exception happening when calling the new operator. I'm
not sure if this is the intended reaction to the situation or is
actually a problem I've got. In any case a different error message
would be helpful. I would like to know your thoughts on this problem.
The situation:
I have an external Library of C Functions and...
|
by: Bob |
last post by:
I have several simple user controls (e.g. header, footer) that have static
content so I thought it would be a good idea to turn on the ouput cache. So
I added <%@ OutputCache Duration="600" Shared="True" VaryByParam="none" %>
to the control. I have a base page class that overrides the Render() method
to load these controls:
protected...
|
by: theta |
last post by:
Hi everyone,
I'm a newbie .NET developer with vb6 experience. I was toying myself with
the Howl open source library for Zeroconf networks and I stumbled across an
exception I can't quite figure out completely.
The library is a .dll and i'm using PInvoke (<DllImport>) to declare the
functions in the library; I've only declared the following so...
| |
by: theta |
last post by:
Hi everyone. I'm a .NET newbie and I have a problem calling DLL functions
from vb .net.
I'm trying to access Howl's Rendezvous.dll
(www.porchdogsoft.com/products/howl/) from managed code. I was trying to
use <DllImport> Functions for that, but I'm having strange glitches when I
try to make it work.
I made a module consisting of these:
|
by: Ryan Liu |
last post by:
I have a program works fine in .NET 1.1 and just recompiled in .NET 2.0
without any code change. Compiles OK, but there is an exeception when
execute it.
Then I remove PK, it works all fine again.
Is this a known bug : PK on auto increase DataColumn in DataTable cause
NullReferenceException?
dcLineId = new DataColumn(LINEID_STR,
|
by: Sagar |
last post by:
Hi.
I am working on a project to migrate a web application from 1.1 to 2.0
Within in the DAL of the application, there is a call to below
function that builds a command object for later use.
Inside this function iam getting a runtime error when the command
object calls the prepare method.
|
by: puzzlecracker |
last post by:
Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an ob
ject.
Here is where I get this:
public void Foo(){
ArrayList list=new ArrayList();
Bar(list); //<== This throws the exception
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |