473,563 Members | 2,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.NullRefe renceException occurred in

Hi I'm a C# .NET newbie doing a minor school project but I'm getting a
strange error message.

'System.NullRef erenceException ' occurred in system.windows. forms.dll
Additional information: Object reference not set to an instance of an
object."

As my references look I seem to be using the old framework(1.0.3 705) for
this, but re-referencing to the newer framework(1.1.4 322) dll's produces the
same error. This happens under all circumstances when I'm trying to compile
a fully managed project. Even from scratch when trying to just compile the
empty form this happens.

If you read the old thread I've included you can see that he changed his
sourcepath for the whole project to something that is not put in the
MyDocuments folders. I did exactly the same thing and it worked, the
question from me is WHY? All other apps (so far) compiles flawless, it's
only these C# Windows Applications Projects that fail.

Regards,

Andreas Wirén

OS : Windows XP Professional SP1 with all the recent hotfixes and updates.

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;

namespace WindowsApplicat ion1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHan dler(this.Form1 _Load);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}

private void Form1_Load(obje ct sender, System.EventArg s e)
{

}
}
}

http://groups.google.se/groups?hl=sv...3D%2522Applica
tion.Run(new%2B Form1())%253B%2 522%2B%2522obje ct%2Breference% 2Bnot%2Bset%252 2
%26hl%3Dsv%26lr %3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D6FAD a.54216%2524g33 .74
9173%2540weber. videotron.net%2 6rnum%3D6
Nov 15 '05 #1
11 3726
Andreas,
You may use non created object.
for example

MyClass myobject;
myobject.MyMeth od();
-- error;

You shoul do:

MyClass myobject;
myobject = new MyClass();
myobject.MyMeth od();

"Andreas Wirén" <an*****@clan.d cs.se> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:HB******** ************@ne wsc.telia.net.. .
Hi I'm a C# .NET newbie doing a minor school project but I'm getting a
strange error message.

'System.NullRef erenceException ' occurred in system.windows. forms.dll
Additional information: Object reference not set to an instance of an
object."

As my references look I seem to be using the old framework(1.0.3 705) for
this, but re-referencing to the newer framework(1.1.4 322) dll's produces the same error. This happens under all circumstances when I'm trying to compile a fully managed project. Even from scratch when trying to just compile the
empty form this happens.

If you read the old thread I've included you can see that he changed his
sourcepath for the whole project to something that is not put in the
MyDocuments folders. I did exactly the same thing and it worked, the
question from me is WHY? All other apps (so far) compiles flawless, it's
only these C# Windows Applications Projects that fail.

Regards,

Andreas Wirén

OS : Windows XP Professional SP1 with all the recent hotfixes and updates.

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;

namespace WindowsApplicat ion1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHan dler(this.Form1 _Load);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}

private void Form1_Load(obje ct sender, System.EventArg s e)
{

}
}
}

http://groups.google.se/groups?hl=sv...3D%2522Applica tion.Run(new%2B Form1())%253B%2 522%2B%2522obje ct%2Breference% 2Bnot%2Bset%252 2 %26hl%3Dsv%26lr %3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D6FAD a.54216%2524g33 .74 9173%2540weber. videotron.net%2 6rnum%3D6

Nov 15 '05 #2
Dmitry Karneyev <ka******@msn.c om> wrote:
Andreas,
You may use non created object.
for example

MyClass myobject;
myobject.MyMeth od();
-- error;

You shoul do:

MyClass myobject;
myobject = new MyClass();
myobject.MyMeth od();


But that's not what's happening here. The code compiles and runs fine.
Note that according to the message, the error occurs during
compilation, not at runtime.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
It appears to give a NullReferenceEx ception from system.windows. forms.dll

If you use Visual Studio 2002 you can't use v1.1.

I'd try to reinstall the framework.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
Hmm, I'm not sure if I know what the difference between runtime and
compilation is. Anyway, after pressing F5 the program launches but "locks"
and the debugger steps in and gives the error message. This is already a
fresh installation of VS.NET. All I've done is a few(4-5) VB apps.

And I really doubt it's an code error as someone said, the error occurs on
this machine I'm on right now, but not on another box, running exactly the
same VS release coupled with the exact same code I posted earlier.

My guess is that something stupid has happened with some of the DLL files or
some other linked files used by the compiler. The other box (that the
compile works on) has a much fresher install of XP (with all hotfixes and
updates) but does not have the SP1 of VS.NET installed.

"Morten Wennevik" <Mo************ @hotmail.com> skrev i meddelandet
news:oprxhz9njt hntkfz@localhos t...
It appears to give a NullReferenceEx ception from system.windows. forms.dll

If you use Visual Studio 2002 you can't use v1.1.

I'd try to reinstall the framework.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #5
Andreas Wirén <an*****@clan.d cs.se> wrote:
Hmm, I'm not sure if I know what the difference between runtime and
compilation is.
If the error occurs when you compile the code, it's a compile-time
error.

If the error occurs when you run the code, it's a run-time error.
Anyway, after pressing F5 the program launches but "locks"
and the debugger steps in and gives the error message. This is already a
fresh installation of VS.NET. All I've done is a few(4-5) VB apps.
Ah - that's a run-time error. (When you say about "the compile works" I
inferred that it was a compile-time error.)
And I really doubt it's an code error as someone said, the error occurs on
this machine I'm on right now, but not on another box, running exactly the
same VS release coupled with the exact same code I posted earlier.

My guess is that something stupid has happened with some of the DLL filesor
some other linked files used by the compiler. The other box (that the
compile works on) has a much fresher install of XP (with all hotfixes and
updates) but does not have the SP1 of VS.NET installed.


It doesn't sound like it's a compiler error. What happens if you
compile it on the "working" machine and then copy the executable which
is produced onto the "broken" machine and run it there?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
The file works flawless when compiled and executed on the "broken" machine.
I'm also not certain if it really goes into runtime, all that happens when I
press F5 is that the debugger points to a line in the code:

static void Main()
{

Application.Run (new Form1());

}<-----

and a messagebox pops up with the error message System.NullRefe rence...

The form do appear in the taskbar though but when clicked it's only white.
Still the only solution to this problem seem to be to move all my project
files to some other folder on the drive, but that seems like a really silly
solution :-)
"Jon Skeet [C# MVP]" <sk***@pobox.co m> skrev i meddelandet
news:MP******** *************** *@msnews.micros oft.com...
Andreas Wirén <an*****@clan.d cs.se> wrote:
Hmm, I'm not sure if I know what the difference between runtime and
compilation is.
If the error occurs when you compile the code, it's a compile-time
error.

If the error occurs when you run the code, it's a run-time error.
Anyway, after pressing F5 the program launches but "locks"
and the debugger steps in and gives the error message. This is already a
fresh installation of VS.NET. All I've done is a few(4-5) VB apps.
Ah - that's a run-time error. (When you say about "the compile works" I
inferred that it was a compile-time error.)
And I really doubt it's an code error as someone said, the error occurs on
this machine I'm on right now, but not on another box, running exactly the
same VS release coupled with the exact same code I posted earlier.

My guess is that something stupid has happened with some of the DLL files or some other linked files used by the compiler. The other box (that the
compile works on) has a much fresher install of XP (with all hotfixes and
updates) but does not have the SP1 of VS.NET installed.


It doesn't sound like it's a compiler error. What happens if you
compile it on the "working" machine and then copy the executable which
is produced onto the "broken" machine and run it there?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7
Andreas Wirén <an*****@clan.d cs.se> wrote:
The file works flawless when compiled and executed on the "broken" machine.
Eh? Do you mean when it's compiled elsewhere and then executed on the
"broken" machine? If it works fine when compiler *and* executed on the
"broken" machine, I can't see what's wrong at all!
I'm also not certain if it really goes into runtime, all that happens when I
press F5 is that the debugger points to a line in the code:

static void Main()
{

Application.Run (new Form1());

}<-----

and a messagebox pops up with the error message System.NullRefe rence...
That's runtime. If it only breaks when you run it, it's runtime.
The form do appear in the taskbar though but when clicked it's only white..
Still the only solution to this problem seem to be to move all my project
files to some other folder on the drive, but that seems like a really silly
solution :-)


Okay, I'm very confused as to what's provoking this now. Could you give
a brief summary of when it works and when it doesn't, on which machine,
etc?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #8
Sorry if I was confusing you :-)

Machine1 (not the broken one) : Compile - OK! , Executing - OK!
Machine2 (the broken one) : Compile - Error!, Executing - Error!

Machine2 (the broken one) while using the binary from Machine1: Executing -
OK!

Hope that clear things out.

Thanks for your time btw! It's not really that big issue but it's annoying
not being able to save documents/projects to whereever you want.
"Jon Skeet [C# MVP]" <sk***@pobox.co m> skrev i meddelandet
news:MP******** *************** *@msnews.micros oft.com...
Andreas Wirén <an*****@clan.d cs.se> wrote:
The file works flawless when compiled and executed on the "broken" machine.

Eh? Do you mean when it's compiled elsewhere and then executed on the
"broken" machine? If it works fine when compiler *and* executed on the
"broken" machine, I can't see what's wrong at all!
I'm also not certain if it really goes into runtime, all that happens when I press F5 is that the debugger points to a line in the code:

static void Main()
{

Application.Run (new Form1());

}<-----

and a messagebox pops up with the error message System.NullRefe rence...
That's runtime. If it only breaks when you run it, it's runtime.
The form do appear in the taskbar though but when clicked it's only white.
Still the only solution to this problem seem to be to move all my project
files to some other folder on the drive, but that seems like a really silly solution :-)


Okay, I'm very confused as to what's provoking this now. Could you give
a brief summary of when it works and when it doesn't, on which machine,
etc?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #9
Andreas Wirén <an*****@clan.d cs.se> wrote:
Sorry if I was confusing you :-)

Machine1 (not the broken one) : Compile - OK! , Executing - OK!
Machine2 (the broken one) : Compile - Error!, Executing - Error!
When you say "Compile - Error!" are you now saying that you *do* get an
error at compile-time?
Thanks for your time btw! It's not really that big issue but it's annoying
not being able to save documents/projects to whereever you want.


It's also *only* when you save the project in My Documents somewhere
that you get the problem, yes?

It does sound highly bizarre to me.

Out of interest, what happens when you have the project in My Documents
but compile the source code from the command line?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9114
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in system.windows.forms.dll
1
5956
by: gregory_may | last post by:
This code seems to "work" but I get the following errors: An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll then this one: An unhandled exception of type 'System.ExecutionEngineException' occurred in system.windows.forms.dll Anyone know how to either trap these errors or prevent them from...
1
536
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "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. Visual Studio's IDE is not allowing me to...
7
3978
by: David Elliott | last post by:
I have created an application that will dynamically load other DLLs (plugins). The new plugin is a winform with an embedded IE Browser. I am wanting to have the form to run in its own thread. This would allow for other plugins and the main application to be free to do other work. I have written a little TestDriver for the plugin and am...
3
1725
by: msnews.microsoft.com | last post by:
actaully the code i have written below is pretty simple and short. no idea why it terminate at run-time with "An unhandled exception of type 'System.NullReferenceException' occurred" Thank you ---code below--- using System;
2
7796
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item in treeview i display the content item in axWebBrowser, i close the sub form normally when i close the main the following error is generated An...
2
2734
by: sxiao | last post by:
Hi, there I got a NullReferenceException when there are more than one users trying to open the same page at the same time. The senerio is: Two users logged into the web application using the Windows domain user account and tried to open the same page which has the databasde query code. When the two user tried to open the same page at the...
9
3162
by: Supra | last post by:
i got error problem.......... 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.. Namespace PirateChat <========== error occurred in here Public Class mainPirateChat
0
2295
by: schoultzy | last post by:
Hello Everyone, I have been trying to figure this one out for two days now. I have created a DataGridView which is populated by an ObjectDataSource. My problem occurs when I attempt to use the Edit feature of the DataGridView. I have set several of the BoundField elements of the DataGridView to ReadOnly="True". When I attempt to use the...
3
22362
by: GS | last post by:
why am i getting A first chance exception of type 'System.NullReferenceException' occurred in myapp.exe below? and what can i do get rid of it? Private Function getPrefxType() As String If bSkipGetListBOxComboBoxValue Then Return "" Try
0
7888
Oralloy
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. ...
0
8106
jinu1996
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...
0
7950
tracyyun
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...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
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...
0
3643
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.