hiya,
I have winforms app that contains buttons.
Any time that I click on any of the buttons, I get an error:
<error>
An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.
<\error>
This error occurs BEFORE, the "Button_click" event fires.
However, despite the fact that I set breakpoints at:
1) "btnClose_Click" event
2) "frmProduct_Closed" event
3) "frmProduct_Closing" event
The app goes straight into a 'System.NullReferenceException' error.The
breakpoints do not even reach the "btnClose_Click" event.I know for a fact
that debugging works on this app.
I am using vis studio 2003 + perfmon
Also, I have added a ".net CLR memory" log to perfmon.
Can anyone suggest which "debug" options will help me drilldown and find
the error, eg callStack, threads?..ATM, I am only familiar with "watch" and
"breakpoints"
To be honest, I am dancing round in the dark.
many thanks,
yogi
john conwell - 05 Apr 2005 17:05 GMT
Hey Chris,
thats a good one. could you post the stack trace? that will tell you
exactly where the exception is being thrown.
What I do in situations like this where an exception is being thrown
somewhere besides my code (in someone else's compiled assembly) is to look
at the stack trace and figure out what class and method the exception is
being thrown from. Then i use Reflector to look at the code of that method
and see what could possibly be the problem.
> hiya,
> I have winforms app that contains buttons.
[quoted text clipped - 28 lines]
> many thanks,
> yogi
Mike Goatly - 05 Apr 2005 17:29 GMT
Hi,
The first thing I'd do is set the CLR to break into code whenever an
exception is thrown - that way you'll see exactly what's throwing the error
(unless it's from someone elses dll - but you should still be able to see
what's causing it in the call stack - I'll explain that in a mo.)
To set the CLR to "break on all errors" you need to go to the Exceptions
window (Debug->Exceptions or Ctrl-Alt-E) , click on the "Common Language
Runtime Exceptions" node in the exceptions list, and change the "When an
exception is thrown" option to "Break into the debugger"
Now run the code again...
When you get the exception, have a look at the call-stack window. (if it's
not visible you can get at it from Debug->Windows->Call Stack) At the top of
the list is the method the exception was raised from. That might provide
some insight into what's going wrong...
Failing that, if you could post the callstack here, someone here might be
able to help a bit more.
Cheers,
Mike
> hiya,
> I have winforms app that contains buttons.
[quoted text clipped - 28 lines]
> many thanks,
> yogi
chris yoker - 07 Apr 2005 09:14 GMT
hiya, ta for the replies..
I followed the advice and tracked it down to a weird 3rd party data
corruption error.Great advice :-)
yogi
jasmin Col - 15 Apr 2005 07:08 GMT
Hi Mike,
I have the same problem as him. I have a wrapper class that is using a
hidden form to wrap ActiveX. I am calling the wrapper from another
executable using new, but Iam getting System.NullReference Exception
object reference not set to an instance of an object (it says the
problem is coming from system.windows.forms.dll) . I am new to C##. I
followed your steps to find the stack trace and this is what I got. Any
ideas of what it means?
- this {System.Windows.Forms.AxHost.ConnectionPointCookie} System.Window
s.Forms.AxHost.ConnectionPointCookie
System.Object {System.Windows.Forms.AxHost.ConnectionPointCookie} Syste
m.Object
- connectionPoint {System.__ComObject} System.Windows.Forms.UnsafeNative
Methods.IConnectionPoint
+ [System.__ComObject] {System.__ComObject} System.__ComObject
cookie 0x621ff90 int
- this {System.Windows.Forms.AxHost.ConnectionPointCookie} System.Window
s.Forms.AxHost.ConnectionPointCookie
System.Object {System.Windows.Forms.AxHost.ConnectionPointCookie} Syste
m.Object
+ connectionPoint {System.__ComObject} System.Windows.Forms.UnsafeNative
Methods.IConnectionPoint
cookie 0x621ff90 int
- ((System.Windows.Forms.Form)(this)) {System.Windows.Forms.AxHost.Conne
ctionPointCookie} System.Windows.Forms.Form
+ [System.Windows.Forms.AxHost.ConnectionPointCookie] {System.Windows.Fo
rms.AxHost.ConnectionPointCookie} System.Windows.Forms.AxHost.Connection
PointCookie
+ System.Windows.Forms.ContainerControl {System.Windows.Forms.AxHost.Con
nectionPointCookie} System.Windows.Forms.ContainerControl
AcceptButton <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.IButtonControl
Active <error: an exception of type: {System.ArgumentException}
occurred> bool
ActiveForm <undefined value> System.Windows.Forms.Form
ActiveMdiChild <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.Form
AllowTransparency <error: an exception of type:
{System.ArgumentException} occurred> bool
AutoScale <error: an exception of type: {System.ArgumentException}
occurred> bool
AutoScaleBaseSize <error: an exception of type:
{System.ArgumentException} occurred> System.Drawing.Size
+ autoScaleBaseSize {Width=0x490074 Height=0x17001d} System.Drawing.Size
AutoScroll <error: an exception of type: {System.ArgumentException}
occurred> bool
BackColor <error: an exception of type: {System.ArgumentException}
occurred> System.Drawing.Color
calledCreateControl true bool
calledMakeVisible false bool
calledOnLoad true bool
CancelButton <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.IButtonControl
ClientSize <error: an exception of type: {System.ArgumentException}
occurred> System.Drawing.Size
ControlBox <error: an exception of type: {System.ArgumentException}
occurred> bool
CreateParams <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.CreateParams
+ ctlClient {System.ComponentModel.ReflectPropertyDescriptor} System.Win
dows.Forms.MdiClient
+ DefaultIcon {System.Drawing.Icon} System.Drawing.Icon
+ defaultIcon {System.Drawing.Icon} System.Drawing.Icon
DefaultImeMode <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.ImeMode
+ defaultRestrictedIcon {System.Drawing.Icon} System.Drawing.Icon
+ DefaultRestrictedIcon {System.Drawing.Icon} System.Drawing.Icon
DefaultSize <error: an exception of type: {System.ArgumentException}
occurred> System.Drawing.Size
DesktopBounds <error: an exception of type: {System.ArgumentException}
occurred> System.Drawing.Rectangle
DesktopLocation <error: an exception of type:
{System.ArgumentException} occurred> System.Drawing.Point
dialogResult 0x9473dd8 System.Windows.Forms.DialogResult
DialogResult <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.DialogResult
EVENT_ACTIVATED {System.Object} System.Object
EVENT_CLOSED {System.Object} System.Object
EVENT_CLOSING {System.Object} System.Object
EVENT_DEACTIVATE {System.Object} System.Object
EVENT_INPUTLANGCHANGE {System.Object} System.Object
EVENT_INPUTLANGCHANGEREQUEST {System.Object} System.Object
EVENT_LOAD {System.Object} System.Object
EVENT_MAXIMIZEDBOUNDSCHANGED {System.Object} System.Object
EVENT_MAXIMUMSIZECHANGED {System.Object} System.Object
EVENT_MDI_CHILD_ACTIVATE {System.Object} System.Object
EVENT_MENUCOMPLETE {System.Object} System.Object
EVENT_MENUSTART {System.Object} System.Object
EVENT_MINIMUMSIZECHANGED {System.Object} System.Object
FormBorderStyle <error: an exception of type:
{System.ArgumentException}
occurred> System.Windows.Forms.FormBorderStyle
+ formState {System.Collections.Specialized.BitVector32} System.Collecti
ons.Specialized.BitVector32
+ FormStateAllowLayered {System.Collections.Specialized.BitVector32.Sect
ion} System.Collections.Specialized.BitVector32.Section
+ FormStateAutoScaling {System.Collections.Specialized.BitVector32.Secti
on} System.Collections.Specialized.BitVector32.Section
+ FormStateBorderStyle {System.Collections.Specialized.BitVector32.Secti
on} System.Collections.Specialized.BitVector32.Section
+ FormStateControlBox {System.Collections.Specialized.BitVector32.Sectio
n} System.Collections.Specialized.BitVector32.Section
+ FormStateHelpButton {System.Collections.Specialized.BitVector32.Sectio
n} System.Collections.Specialized.BitVector32.Section
+ FormStateIconSet {System.Collections.Specialized.BitVector32.Section}
System.Collections.Specialized.BitVector32.Section
+ FormStateIsActive {System.Collections.Specialized.BitVector32.Section}
System.Collections.Specialized.BitVector32.Section
+ FormStateIsRestrictedWindow {System.Collections.Specialized.BitVector3
2.Section} System.Collections.Specialized.BitVector32.Section
+ FormStateIsRestrictedWindowChecked {System.Collections.Specialized.Bit
Vector32.Section} System.Collections.Specialized.BitVector32.Section
+ FormStateIsTextEmpty {System.Collections.Specialized.BitVector32.Secti
on} System.Collections.Specialized.BitVector32.Section
+ FormStateIsWindowActivated {System.Collections.Specialized.BitVector32
.Section} System.Collections.Specialized.BitVector32.Section
+ FormStateKeyPreview {System.Collections.Specialized.BitVector32.Sectio
n} System.Collections.Specialized.BitVector32.Section
+ FormStateLayered {System.Collections.Specialized.BitVector32.Section}
System.Collections.Specialized.BitVector32.Section
+ FormStateMaximizeBox {System.Collections.Specialized.BitVector32.Secti
on} System.Collections.Specialized.BitVector32.Section
+ FormStateMdiChildMax {System.Collections.Specialized.BitVector32.Secti
on} System.Collections.Specialized.BitVector32.Section
+ FormStateMinimizeBox {System.Collections.Specialized.BitVector32.Secti
on} System.Collections.Specialized.BitVector32.Section
+ FormStateRenderSizeGrip {System.Collections.Specialized.BitVector32.Se
ction} System.Collections.Specialized.BitVector32.Section
+ FormStateSetClientSize {System.Collections.Specialized.BitVector32.Sec
tion} System.Collections.Specialized.BitVector32.Section
+ FormStateShowWindowOnCreate {System.Collections.Specialized.BitVector3
2.Section} System.Collections.Specialized.BitVector32.Section
+ FormStateSizeGripStyle {System.Collections.Specialized.BitVector32.Sec
tion} System.Collections.Specialized.BitVector32.Section
+ FormStateStartPos {System.Collections.Specialized.BitVector32.Section}
System.Collections.Specialized.BitVector32.Section
+ FormStateSWCalled {System.Collections.Specialized.BitVector32.Section}
System.Collections.Specialized.BitVector32.Section
+ FormStateTaskBar {System.Collections.Specialized.BitVector32.Section}
System.Collections.Specialized.BitVector32.Section
+ FormStateTopMost {System.Collections.Specialized.BitVector32.Section}
System.Collections.Specialized.BitVector32.Section
+ FormStateWindowState {System.Collections.Specialized.BitVector32.Secti
on} System.Collections.Specialized.BitVector32.Section
HasMenu <error: an exception of type: {System.ArgumentException}
occurred> bool
HelpButton <error: an exception of type: {System.ArgumentException}
occurred> bool
+ icon {...} System.Drawing.Icon
Icon <error: an exception of type: {System.ArgumentException}
occurred> System.Drawing.Icon
IsMdiChild <error: an exception of type: {System.ArgumentException}
occurred> bool
IsMdiChildAndNotVisible <error: an exception of type:
{System.ArgumentException} occurred> bool
IsMdiContainer <error: an exception of type: {System.ArgumentException}
occurred> bool
IsRestrictedWindow <error: an exception of type:
{System.ArgumentException} occurred> bool
KeyPreview <error: an exception of type: {System.ArgumentException}
occurred> bool
MaximizeBox <error: an exception of type: {System.ArgumentException}
occurred> bool
MaximizedBounds <error: an exception of type:
{System.ArgumentException} occurred> System.Drawing.Rectangle
MaximumSize <error: an exception of type: {System.ArgumentException}
occurred> System.Drawing.Size
MdiChildren <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.Form[]
MdiParent <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.Form
MdiParentInternal <error: an exception of type:
{System.ArgumentException} occurred> System.Windows.Forms.Form
Menu <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.MainMenu
MergedMenu <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.MainMenu
MinimizeBox <error: an exception of type: {System.ArgumentException}
occurred> bool
MinimumSize <error: an exception of type: {System.ArgumentException}
occurred> System.Drawing.Size
Modal <error: an exception of type: {System.ArgumentException}
occurred> bool
Opacity <error: an exception of type: {System.ArgumentException}
occurred> double
OpacityAsByte <error: an exception of type: {System.ArgumentException}
occurred> byte
OwnedForms <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.Form[]
Owner <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.Form
OwnerInternal <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.Form
ParentInternal <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.Control
PropAcceptButton 0x0 int
PropActiveMdiChild 0x11 int
PropCancelButton 0x1 int
PropCurMenu 0x6 int
PropDefaultButton 0x2 int
PropDialogOwner 0x3 int
PropDummyMenu 0x5 int
PropFormMdiParent 0x10 int
PropMainMenu 0x4 int
PropMaximizedBounds 0xa int
PropMaxTrackSizeHeight 0xf int
PropMaxTrackSizeWidth 0xe int
PropMergedMenu 0x7 int
PropMinTrackSizeHeight 0xd int
PropMinTrackSizeWidth 0xc int
PropOpacity 0x12 int
PropOwnedForms 0x9 int
PropOwnedFormsCount 0xb int
PropOwner 0x8 int
PropSecurityTip 0x14 int
PropTransparencyKey 0x13 int
+ restoredWindowBounds {X=0x80103 Y=0x0 Width=0xc315f34
Height=0x943d720} System.Drawing.Rectangle
restoredWindowBoundsSpecified 0x945f2b0 System.Windows.Forms.BoundsSpec
ified
securitySite "ᾌӊŸŸ\0\0璀?\0
\0\0\0ⵗ閽\0\0\0\0\0\0\0\0\0\0\0\0Ÿ઼?M
64; \0\0\0\0牰?\0\0\0\0\0" string
securityZone "ؼ笷게Ÿ게ŸᲔ
ᱨ
\0\0\0\0ꕻ譬ā\0\0\0\0\0\0\0\0\0\0\0霸Ÿᅆ
0;Ÿ\0\0\0\0麬Ÿ걌Ÿ걤Ÿ\0\0\0\0\0\0\0
\0F\0\0" string
ShowInTaskbar <error: an exception of type: {System.ArgumentException}
occurred> bool
ShowParams <error: an exception of type: {System.ArgumentException}
occurred> int
Size <error: an exception of type: {System.ArgumentException}
occurred> System.Drawing.Size
SizeGripSize 0x10 int
SizeGripStyle <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.SizeGripStyle
+ smallIcon {...} System.Drawing.Icon
StartPosition <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.FormStartPosition
TabIndex <error: an exception of type: {System.ArgumentException}
occurred> int
TopLevel <error: an exception of type: {System.ArgumentException}
occurred> bool
TopMost <error: an exception of type: {System.ArgumentException}
occurred> bool
TransparencyKey <error: an exception of type:
{System.ArgumentException} occurred> System.Drawing.Color
updateMenuHandlesDeferred true bool
updateMenuHandlesSuspendCount 0x0 byte
useMdiChildProc false bool
userWindowText "ؼ笷콨Ÿ콨Ÿᦀ
ᥔ
\0\0\0\0ȗஈā\0\0\0\0\0\0\0\0\0\0\0霸Ÿ⁘&#
151;\0\0\0\0ꋌŸ켨Ÿ콀Ÿ\0\0\0\0\0\0\0\0F\
0\0" string
WindowState <error: an exception of type: {System.ArgumentException}
occurred> System.Windows.Forms.FormWindowState
WindowText <error: an exception of type: {System.ArgumentException}
occurred> string
+ this {System.Windows.Forms.AxHost.ConnectionPointCookie} System.Window
s.Forms.AxHost.ConnectionPointCook