PC Review


Reply
Thread Tools Rate Thread

Object Reference Error Before Running The Application

 
 
Jeff
Guest
Posts: n/a
 
      5th Mar 2004
I'm getting an Object Reference error before I even run my app, and
I'm not sure where to look to find the cause. I'd appreciate your
help.

When I open my Windows Application project, the following Microsoft
Development Environment error message displays:

"Object reference not set to an instance of an object."

Then when I access the design view of one of my forms, the controls on
the form are hidden behind an error 'display' showing the text at the
end of this post. When I run the app, it seems to run OK. When I
open other projects, I don't get the error, so I'm guessing it's
caused by something in my app. But it would seem that Debug is of no
help, since the error occurs without running the app, and no error
appears when I run the app.

Interesting additional observation: The problem only occurs when I
open the project to a class or module code window (since it was the
active window when I last closed the project). When I open the
project to a design view of a form, the error doesn't appear. Oh, and
I've also tried reinstalling/repairing Visual Studio, and that hasn't
helped. I'm using VB.NET.

Any suggestions???

Thanks for your help.

- Jeff


Here's the error text displayed on the form:

System.NullReferenceException: Object reference not set to an instance
of an object.
at ControlInfoView.Connect.cc1dac46909c42ab()
at ControlInfoView.Connect.dd3392f59d8e3f48(Object e0292b9ed559da7d,
EventArgs fbf34718e704c6bc)
at System.Windows.Forms.Control.OnResize(EventArgs e)
at System.Windows.Forms.Form.OnResize(EventArgs e)
at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32
width, Int32 height, Int32 clientWidth, Int32 clientHeight)
at System.Windows.Forms.Control.UpdateBounds()
at System.Windows.Forms.Control.WmMove(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Design.DesignerWindowTarget.DefWndProc(Message&
m)
at System.Windows.Forms.Design.ControlDesigner.DefWndProc(Message& m)
at System.Windows.Forms.Design.ControlDesigner.WndProc(Message& m)
at System.Windows.Forms.Design.ParentControlDesigner.WndProc(Message&
m)
at System.Windows.Forms.Design.ScrollableControlDesigner.WndProc(Message&
m)
at System.Windows.Forms.Design.DocumentDesigner.WndProc(Message& m)
at System.Windows.Forms.Design.FormDocumentDesigner.WndProc(Message&
m)
at System.Windows.Forms.Design.DesignerWindowTarget.OnMessage(Message&
m)
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      5th Mar 2004
* (E-Mail Removed) (Jeff) scripsit:
> I'm getting an Object Reference error before I even run my app, and
> I'm not sure where to look to find the cause. I'd appreciate your
> help.


Post the question to this group:

<news:microsoft.public.dotnet.framework.windowsforms>

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
 
Reply With Quote
 
 
 
 
Stephen Muecke
Guest
Posts: n/a
 
      5th Mar 2004
Jeff,
I've found this is usually the result of a declaring a class (but not
initiating it), and refering to it in the Load event of the form,
particularly if it inherits from another form

eg
Public Class Form1
.......

Private m_MyObject as MyObject

Private Sub Form_Load(ByVal sender as Object, ByVal e as EventArgs)
Handles MyBase.Load
'Set the value of MyObject or so something with MyObject
End Sub

The problem can be solved if you initialize MyObject when you declare it ,
ie
Private m_MyObject as New MyObject

(Check base classes and make sure you build the project after making the
changes)

Stephen


"Jeff" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm getting an Object Reference error before I even run my app, and
> I'm not sure where to look to find the cause. I'd appreciate your
> help.
>
> When I open my Windows Application project, the following Microsoft
> Development Environment error message displays:
>
> "Object reference not set to an instance of an object."
>
> Then when I access the design view of one of my forms, the controls on
> the form are hidden behind an error 'display' showing the text at the
> end of this post. When I run the app, it seems to run OK. When I
> open other projects, I don't get the error, so I'm guessing it's
> caused by something in my app. But it would seem that Debug is of no
> help, since the error occurs without running the app, and no error
> appears when I run the app.
>
> Interesting additional observation: The problem only occurs when I
> open the project to a class or module code window (since it was the
> active window when I last closed the project). When I open the
> project to a design view of a form, the error doesn't appear. Oh, and
> I've also tried reinstalling/repairing Visual Studio, and that hasn't
> helped. I'm using VB.NET.
>
> Any suggestions???
>
> Thanks for your help.
>
> - Jeff
>
>
> Here's the error text displayed on the form:
>
> System.NullReferenceException: Object reference not set to an instance
> of an object.
> at ControlInfoView.Connect.cc1dac46909c42ab()
> at ControlInfoView.Connect.dd3392f59d8e3f48(Object e0292b9ed559da7d,
> EventArgs fbf34718e704c6bc)
> at System.Windows.Forms.Control.OnResize(EventArgs e)
> at System.Windows.Forms.Form.OnResize(EventArgs e)
> at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
> at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32
> width, Int32 height, Int32 clientWidth, Int32 clientHeight)
> at System.Windows.Forms.Control.UpdateBounds()
> at System.Windows.Forms.Control.WmMove(Message& m)
> at System.Windows.Forms.Control.WndProc(Message& m)
> at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
> at System.Windows.Forms.ContainerControl.WndProc(Message& m)
> at System.Windows.Forms.Form.WndProc(Message& m)
> at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
> at System.Windows.Forms.Design.DesignerWindowTarget.DefWndProc(Message&
> m)
> at System.Windows.Forms.Design.ControlDesigner.DefWndProc(Message& m)
> at System.Windows.Forms.Design.ControlDesigner.WndProc(Message& m)
> at System.Windows.Forms.Design.ParentControlDesigner.WndProc(Message&
> m)
> at System.Windows.Forms.Design.ScrollableControlDesigner.WndProc(Message&
> m)
> at System.Windows.Forms.Design.DocumentDesigner.WndProc(Message& m)
> at System.Windows.Forms.Design.FormDocumentDesigner.WndProc(Message&
> m)
> at System.Windows.Forms.Design.DesignerWindowTarget.OnMessage(Message&
> m)



 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      9th Mar 2004
Well, the problem is still occurring, but I've done some additional
testing.

(First, my project doesn't have the type of construct that Stephan
describes in his post. But thanks for the suggestion, Stephan.)

I've distilled the problem down to the MainMenu control. It may occur
with other controls; I just haven't tested beyond this one. I've
re-created the problem by simply creating a new project and adding a
MainMenu control to Form1. Here's what I've done:

1. Start a new Windows Application: (I named mine MenuTest)
(A new project is created, and the IDE opens showing Form1)

2. Add a Main Menu to Form1 by double-clicking the MainMenu control in
the toolbox

3. Save the Project

4. Build the Solution

5. Exit VB.NET

6. Re-Launch VB.NET, open the project

7. View the Design view of Form1

8. Click the MainMenu1 control --> Error!

Microsoft Development Environment
Object reference not set to an instance of an object.

I then added a menu item, saved/built, closed/opened the IDE.
Clicking the MainMenu1 control did NOT raise the error. But if I then
viewed the code window for Form1 and then closed/opened the IDE (so
the code window was displayed as the most recent document), the error
was displayed.

If I delete the suo file and re-open the project, the problem doesn't
occur -- until I next open the project again, when the problem recurs.

I still don't know how to solve the problem! Does anyone have any
suggestions?

- Jeff

"Stephen Muecke" <(E-Mail Removed)> wrote in message news:<OM3WX$(E-Mail Removed)>...
> Jeff,
> I've found this is usually the result of a declaring a class (but not
> initiating it), and refering to it in the Load event of the form,
> particularly if it inherits from another form
>
> eg
> Public Class Form1
> .......
>
> Private m_MyObject as MyObject
>
> Private Sub Form_Load(ByVal sender as Object, ByVal e as EventArgs)
> Handles MyBase.Load
> 'Set the value of MyObject or so something with MyObject
> End Sub
>
> The problem can be solved if you initialize MyObject when you declare it ,
> ie
> Private m_MyObject as New MyObject
>
> (Check base classes and make sure you build the project after making the
> changes)
>
> Stephen
>
>
> "Jeff" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I'm getting an Object Reference error before I even run my app, and
> > I'm not sure where to look to find the cause. I'd appreciate your
> > help.
> >
> > When I open my Windows Application project, the following Microsoft
> > Development Environment error message displays:
> >
> > "Object reference not set to an instance of an object."
> >
> > Then when I access the design view of one of my forms, the controls on
> > the form are hidden behind an error 'display' showing the text at the
> > end of this post. When I run the app, it seems to run OK. When I
> > open other projects, I don't get the error, so I'm guessing it's
> > caused by something in my app. But it would seem that Debug is of no
> > help, since the error occurs without running the app, and no error
> > appears when I run the app.
> >
> > Interesting additional observation: The problem only occurs when I
> > open the project to a class or module code window (since it was the
> > active window when I last closed the project). When I open the
> > project to a design view of a form, the error doesn't appear. Oh, and
> > I've also tried reinstalling/repairing Visual Studio, and that hasn't
> > helped. I'm using VB.NET.
> >
> > Any suggestions???
> >
> > Thanks for your help.
> >
> > - Jeff
> >
> >
> > Here's the error text displayed on the form:
> >
> > System.NullReferenceException: Object reference not set to an instance
> > of an object.
> > at ControlInfoView.Connect.cc1dac46909c42ab()
> > at ControlInfoView.Connect.dd3392f59d8e3f48(Object e0292b9ed559da7d,
> > EventArgs fbf34718e704c6bc)
> > at System.Windows.Forms.Control.OnResize(EventArgs e)
> > at System.Windows.Forms.Form.OnResize(EventArgs e)
> > at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
> > at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32
> > width, Int32 height, Int32 clientWidth, Int32 clientHeight)
> > at System.Windows.Forms.Control.UpdateBounds()
> > at System.Windows.Forms.Control.WmMove(Message& m)
> > at System.Windows.Forms.Control.WndProc(Message& m)
> > at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
> > at System.Windows.Forms.ContainerControl.WndProc(Message& m)
> > at System.Windows.Forms.Form.WndProc(Message& m)
> > at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
> > at System.Windows.Forms.Design.DesignerWindowTarget.DefWndProc(Message&
> > m)
> > at System.Windows.Forms.Design.ControlDesigner.DefWndProc(Message& m)
> > at System.Windows.Forms.Design.ControlDesigner.WndProc(Message& m)
> > at System.Windows.Forms.Design.ParentControlDesigner.WndProc(Message&
> > m)
> > at System.Windows.Forms.Design.ScrollableControlDesigner.WndProc(Message&
> > m)
> > at System.Windows.Forms.Design.DocumentDesigner.WndProc(Message& m)
> > at System.Windows.Forms.Design.FormDocumentDesigner.WndProc(Message&
> > m)
> > at System.Windows.Forms.Design.DesignerWindowTarget.OnMessage(Message&
> > m)

 
Reply With Quote
 
=?Utf-8?B?RXJpYyBGcmFueg==?=
Guest
Posts: n/a
 
      9th Mar 2004
Well
The windows forms designer has to create an instance of the form and all of the controls in the control collection in order to show it in the designer. Within the constructor of your form, you may be evaluating code which relies on runtime information, causing an error. Sometimes, putting similar code in the LoadEvent of a base form will have the same effect

-Eri
implemental.com
 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      9th Mar 2004
Thanks for your response, Eric -

The only code in my simple example is that generated automatically by the
Windows Form Designer. Specifically (after I added the menu item):

Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem

And in Sub InitializeComponent():

Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.Text = "File"

Me.Menu = Me.MainMenu1


[There is no code in the form's load event -- or elsewhere, for that matter.
All I did was add a mainmenu and a menu item to the default form.]

Any suggestions re how I can solve the problem?? Do you see anything that
would rely on runtime information (as you suggested)?

Thanks again.

- Jeff


"Eric Franz" <(E-Mail Removed)> wrote in message
news:A5AE7C9F-BCED-4607-B232-(E-Mail Removed)...
> Well,
> The windows forms designer has to create an instance of the form and all

of the controls in the control collection in order to show it in the
designer. Within the constructor of your form, you may be evaluating code
which relies on runtime information, causing an error. Sometimes, putting
similar code in the LoadEvent of a base form will have the same effect.
>
> -Eric
> implemental.com



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
when i reference a com object by regsvr32 it then find it in the COM tab, it works ok. but when i reference a com object by referencing the .dll file i get this error in my C# application: DR Microsoft Dot NET 1 19th Jan 2008 06:01 PM
when i reference a com object by regsvr32 it then find it in the COM tab, it works ok. but when i reference a com object by referencing the .dll file i get this error in my C# application: DR Microsoft C# .NET 1 18th Jan 2008 09:18 AM
when i reference a com object by regsvr32 it then find it in the COM tab, it works ok. but when i reference a com object by referencing the .dll file i get this error in my C# application: DR Microsoft Dot NET Framework 0 18th Jan 2008 04:22 AM
Releasing reference to the Application object before exiting cgr Microsoft Excel Programming 2 9th Jan 2006 11:45 PM
Object Reference Error Before Running The Application Jeff Microsoft Dot NET Framework Forms 2 9th Mar 2004 02:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:36 PM.