System.NullReferenceException

T

Terrence

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

I am sure this is a simple fix, but I cannot find a answer.

Terrence
 
J

Jim Blizzard [MSFT]

Can you post the rest of your code? Without it, it's difficult to tell
what's going on....

Thanks,
- bliz
--
Jim Blizzard
Sr .NET Developer Evangelist
Microsoft

Your Potential. Our Passion.

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only, so that others may benefit. Thanks.


--------------------
 
J

Jim Blizzard [MSFT]

Thanks for posting the code. It appears as though there's a bug in the
InitializeComponent method. You may want to take a look at the book
publisher's or author's web site to see if there's some erratta information
with corrections to the code.

Unfortunately I can't tell what's going on without even more information
regarding external references to things such as
AuthorsWinClient.localhost.authors1

Good luck!
-bliz

--
Jim Blizzard
Sr .NET Developer Evangelist
Microsoft

Your Potential. Our Passion.

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only, so that others may benefit. Thanks.


--------------------
Content-Class: urn:content-classes:message
From: "Terrence" <[email protected]>
Sender: "Terrence" <[email protected]>
References: <[email protected]>
Subject: RE: System.NullReferenceException
Date: Thu, 3 Jul 2003 07:10:32 -0700
Lines: 319
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNBbN3Ax2+BDkEpRLCp7Qep1YyJAw==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa09.phx.gbl
Xref: cpmsftngxa09.phx.gbl microsoft.public.dotnet.general:14548
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.general

Here is the code; I will mark the line where the execution
stops with <====

Also, I have included the contents of the Debug window
following the code.
============================ CODE ======================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace AuthorsWinClient
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid
dataGrid1;
private System.Windows.Forms.Button
SaveData;
private System.Windows.Forms.Button
LoadData;
private
AuthorsWinClient.localhost.authors1 AuthorData;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container
components = null;

public frmMain()
{
//
// Required for Windows Form
Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code
after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool
disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose
();
}
}
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 InitializeComponent()
{
this.dataGrid1 = new
System.Windows.Forms.DataGrid();
this.AuthorData = new
AuthorsWinClient.localhost.authors1();
this.SaveData = new
System.Windows.Forms.Button();
this.LoadData = new
System.Windows.Forms.Button();

((System.ComponentModel.ISupportInitialize)
(this.dataGrid1)).BeginInit();

((System.ComponentModel.ISupportInitialize)
(this.AuthorData)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember
= "authors";
this.dataGrid1.DataSource =
this.AuthorData;
this.dataGrid1.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new
System.Drawing.Point(8, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new
System.Drawing.Size(344, 184);
this.dataGrid1.TabIndex = 0;
//
// AuthorData
//
this.AuthorData.DataSetName
= "authors1";
this.AuthorData.Locale = new
System.Globalization.CultureInfo("en-US");
//
// SaveData
//
this.SaveData.Location = new
System.Drawing.Point(216, 208);
this.SaveData.Name = "SaveData";
this.SaveData.Size = new
System.Drawing.Size(96, 24);
this.SaveData.TabIndex = 1;
this.SaveData.Text = "Save";
this.SaveData.Click += new
System.EventHandler(this.SaveData_Click);
//
// LoadData
//
this.LoadData.Location = new
System.Drawing.Point(40, 208);
this.LoadData.Name = "LoadData";
this.LoadData.Size = new
System.Drawing.Size(80, 24);
this.LoadData.TabIndex = 2;
this.LoadData.Text = "Load";
this.LoadData.Click += new
System.EventHandler(this.LoadData_Click);
//
// frmMain
//
this.AutoScaleBaseSize = new
System.Drawing.Size(5, 13);
this.ClientSize = new
System.Drawing.Size(360, 245);
this.Controls.Add(this.LoadData);
this.Controls.Add(this.SaveData);
this.Controls.Add(this.dataGrid1);
this.Name = "frmMain";
this.Text = "Form Main";

((System.ComponentModel.ISupportInitialize)
(this.dataGrid1)).EndInit();

((System.ComponentModel.ISupportInitialize)
(this.AuthorData)).EndInit();
this.ResumeLayout(false);

}
#endregion

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

private void LoadData_Click(object sender,
System.EventArgs e)
{

AuthorsWinClient.localhost.AuthorsService ws =
new
AuthorsWinClient.localhost.AuthorsService();
ws.Credentials =
System.Net.CredentialCache.DefaultCredentials;
AuthorData.Merge(ws.GetAuthors());
}

private void SaveData_Click(object sender,
System.EventArgs e)
{

AuthorsWinClient.localhost.AuthorsService ws =
new
AuthorsWinClient.localhost.AuthorsService();
ws.Credentials =
System.Net.CredentialCache.DefaultCredentials;

AuthorsWinClient.localhost.authors1 diffAuthors =
new
AuthorsWinClient.localhost.authors1();
diffAuthors.Merge
(AuthorData.GetChanges());
diffAuthors = ws.UpdateAuthors
(diffAuthors);
AuthorData.Merge(diffAuthors);
}
}
}
======================= DEBUG ==========================
'DefaultDomain':
Loaded 'c:\winnt\microsoft.net\framework\v1.1.4322
\mscorlib.dll', No symbols loaded.
'AuthorsWinClient': Loaded 'C:\Documents and
Settings\tdaniel\My Documents\Visual Studio
Projects\AuthorWebService\AuthorsWinClient\bin\Debug\Author
sWinClient.exe', Symbols loaded.
'AuthorsWinClient.exe':
Loaded 'c:\winnt\assembly\gac\system.windows.forms\1.0.5000
.0__b77a5c561934e089\system.windows.forms.dll', No symbols
loaded.
'AuthorsWinClient.exe':
Loaded 'c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c5619
34e089\system.dll', No symbols loaded.
'AuthorsWinClient.exe':
Loaded 'c:\winnt\assembly\gac\system.drawing\1.0.5000.0__b0
3f5f7f11d50a3a\system.drawing.dll', No symbols loaded.
'AuthorsWinClient.exe':
Loaded 'c:\winnt\assembly\gac\system.data\1.0.5000.0__b77a5
c561934e089\system.data.dll', No symbols loaded.
'AuthorsWinClient.exe':
Loaded 'c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a5c
561934e089\system.xml.dll', No symbols loaded.
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.


Unhandled Exception: System.NullReferenceException: Object
reference not set to an instance of an object.
at System.Windows.Forms.SafeNativeMethods.ShowWindow
(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean
value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean
value)
at System.Windows.Forms.Control.set_Visible(Boolean
value)
at
System.Windows.Forms.ThreadContext.RunMessageLoopInner
(Int32 reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop
(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at AuthorsWinClient.frmMain.Main() in c:\documents and
settings\tdaniel\my documents\visual studio
projects\authorwebservice\authorswinclient\form1.cs:line
121The program '[3084] AuthorsWinClient.exe' has exited
with code 0 (0x0).
 
J

Jim Blizzard [MSFT]

Let me take a look at the sample app.

Thanks,
- bliz
--
Jim Blizzard
Sr .NET Developer Evangelist
Microsoft

Your Potential. Our Passion.

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only, so that others may benefit. Thanks.


--------------------
Content-Class: urn:content-classes:message
From: "Terrence" <[email protected]>
Sender: "Terrence" <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: RE: System.NullReferenceException
Date: Thu, 3 Jul 2003 08:01:12 -0700
Lines: 397
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcNBc/GGEtBG3tHWTS2AU6Ql41txxg==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa09.phx.gbl
Xref: cpmsftngxa09.phx.gbl microsoft.public.dotnet.general:14562
NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
X-Tomcat-NG: microsoft.public.dotnet.general

Jim,

This is the code from MS VS.NET 2003 documentation/C#
Walkthrough/Simple Distributed App - Typed verbatim. I
have done the same walkthrough using VS.NET (on home box)
and it ran. Any thoughts?
-----Original Message-----
Thanks for posting the code. It appears as though there's a bug in the
InitializeComponent method. You may want to take a look at the book
publisher's or author's web site to see if there's some erratta information
with corrections to the code.

Unfortunately I can't tell what's going on without even more information
regarding external references to things such as
AuthorsWinClient.localhost.authors1

Good luck!
-bliz

--
Jim Blizzard
Sr .NET Developer Evangelist
Microsoft

Your Potential. Our Passion.

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only, so that others may benefit. Thanks.


--------------------
Content-Class: urn:content-classes:message
From: "Terrence" <[email protected]>
Sender: "Terrence" <[email protected]>
References: <[email protected]>
Subject: RE: System.NullReferenceException
Date: Thu, 3 Jul 2003 07:10:32 -0700
Lines: 319
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNBbN3Ax2+BDkEpRLCp7Qep1YyJAw==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa09.phx.gbl
Xref: cpmsftngxa09.phx.gbl microsoft.public.dotnet.general:14548
NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
X-Tomcat-NG: microsoft.public.dotnet.general

Here is the code; I will mark the line where the execution
stops with <====

Also, I have included the contents of the Debug window
following the code.
============================ CODE ======================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace AuthorsWinClient
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid
dataGrid1;
private System.Windows.Forms.Button
SaveData;
private System.Windows.Forms.Button
LoadData;
private
AuthorsWinClient.localhost.authors1 AuthorData;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container
components = null;

public frmMain()
{
//
// Required for Windows Form
Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code
after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool
disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose
();
}
}
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 InitializeComponent()
{
this.dataGrid1 = new
System.Windows.Forms.DataGrid();
this.AuthorData = new
AuthorsWinClient.localhost.authors1();
this.SaveData = new
System.Windows.Forms.Button();
this.LoadData = new
System.Windows.Forms.Button();

((System.ComponentModel.ISupportInitialize)
(this.dataGrid1)).BeginInit();

((System.ComponentModel.ISupportInitialize)
(this.AuthorData)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember
= "authors";
this.dataGrid1.DataSource =
this.AuthorData;
this.dataGrid1.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new
System.Drawing.Point(8, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new
System.Drawing.Size(344, 184);
this.dataGrid1.TabIndex = 0;
//
// AuthorData
//
this.AuthorData.DataSetName
= "authors1";
this.AuthorData.Locale = new
System.Globalization.CultureInfo("en-US");
//
// SaveData
//
this.SaveData.Location = new
System.Drawing.Point(216, 208);
this.SaveData.Name = "SaveData";
this.SaveData.Size = new
System.Drawing.Size(96, 24);
this.SaveData.TabIndex = 1;
this.SaveData.Text = "Save";
this.SaveData.Click += new
System.EventHandler(this.SaveData_Click);
//
// LoadData
//
this.LoadData.Location = new
System.Drawing.Point(40, 208);
this.LoadData.Name = "LoadData";
this.LoadData.Size = new
System.Drawing.Size(80, 24);
this.LoadData.TabIndex = 2;
this.LoadData.Text = "Load";
this.LoadData.Click += new
System.EventHandler(this.LoadData_Click);
//
// frmMain
//
this.AutoScaleBaseSize = new
System.Drawing.Size(5, 13);
this.ClientSize = new
System.Drawing.Size(360, 245);
this.Controls.Add(this.LoadData);
this.Controls.Add(this.SaveData);
this.Controls.Add(this.dataGrid1);
this.Name = "frmMain";
this.Text = "Form Main";

((System.ComponentModel.ISupportInitialize)
(this.dataGrid1)).EndInit();

((System.ComponentModel.ISupportInitialize)
(this.AuthorData)).EndInit();
this.ResumeLayout(false);

}
#endregion

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

private void LoadData_Click(object sender,
System.EventArgs e)
{

AuthorsWinClient.localhost.AuthorsService ws =
new
AuthorsWinClient.localhost.AuthorsService();
ws.Credentials =
System.Net.CredentialCache.DefaultCredentials;
AuthorData.Merge(ws.GetAuthors());
}

private void SaveData_Click(object sender,
System.EventArgs e)
{

AuthorsWinClient.localhost.AuthorsService ws =
new
AuthorsWinClient.localhost.AuthorsService();
ws.Credentials =
System.Net.CredentialCache.DefaultCredentials;

AuthorsWinClient.localhost.authors1 diffAuthors =
new
AuthorsWinClient.localhost.authors1();
diffAuthors.Merge
(AuthorData.GetChanges());
diffAuthors = ws.UpdateAuthors
(diffAuthors);
AuthorData.Merge(diffAuthors);
}
}
}
======================= DEBUG ==========================
'DefaultDomain':
Loaded 'c:\winnt\microsoft.net\framework\v1.1.4322
\mscorlib.dll', No symbols loaded.
'AuthorsWinClient': Loaded 'C:\Documents and
Settings\tdaniel\My Documents\Visual Studio
Projects\AuthorWebService\AuthorsWinClient\bin\Debug\Auth or
sWinClient.exe', Symbols loaded.
'AuthorsWinClient.exe':
Loaded 'c:\winnt\assembly\gac\system.windows.forms\1.0.50 00
.0__b77a5c561934e089\system.windows.forms.dll', No symbols
loaded.
'AuthorsWinClient.exe':
Loaded 'c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c56 19
34e089\system.dll', No symbols loaded.
'AuthorsWinClient.exe':
Loaded 'c:\winnt\assembly\gac\system.drawing\1.0.5000.0__ b0
3f5f7f11d50a3a\system.drawing.dll', No symbols loaded.
'AuthorsWinClient.exe':
Loaded 'c:\winnt\assembly\gac\system.data\1.0.5000.0__b77 a5
c561934e089\system.data.dll', No symbols loaded.
'AuthorsWinClient.exe':
Loaded 'c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a 5c
561934e089\system.xml.dll', No symbols loaded.
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.


Unhandled Exception: System.NullReferenceException: Object
reference not set to an instance of an object.
at System.Windows.Forms.SafeNativeMethods.ShowWindow
(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore (Boolean
value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean
value)
at System.Windows.Forms.Control.set_Visible(Boolean
value)
at
System.Windows.Forms.ThreadContext.RunMessageLoopInner
(Int32 reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop
(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at AuthorsWinClient.frmMain.Main() in c:\documents and
settings\tdaniel\my documents\visual studio
projects\authorwebservice\authorswinclient\form1.cs:line
121The program '[3084] AuthorsWinClient.exe' has exited
with code 0 (0x0).


-----Original Message-----
Can you post the rest of your code? Without it, it's
difficult to tell
what's going on....

Thanks,
- bliz
--
Jim Blizzard
Sr .NET Developer Evangelist
Microsoft

Your Potential. Our Passion.

This posting is provided "AS IS" with no warranties, and
confers no rights.
Please reply to newsgroups only, so that others may
benefit. Thanks.


--------------------
Content-Class: urn:content-classes:message
From: "Terrence" <[email protected]>
Sender: "Terrence" <[email protected]>
Subject: System.NullReferenceException
Date: Wed, 2 Jul 2003 20:14:49 -0700
Lines: 14
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcNBEUNX0JWNsBAcSKah7zscfgzN3g==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa09.phx.gbl
Xref: cpmsftngxa09.phx.gbl
microsoft.public.dotnet.general:14499
NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
X-Tomcat-NG: microsoft.public.dotnet.general

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

I am sure this is a simple fix, but I cannot find a
answer.

Terrence


.

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top