Click to See Complete Forum and Search --> : Object reference not set to an instance of an object.


neil
01-06-2004, 04:29 AM
Its been a while since I coded in ASP, but now with ASP you get these fancy error msgs, I'm just unsure whats causing the error. Its not my code so I searched all files in the directory i was working on for "InitializeComponent()" and couldn't find anything. also what does the .cs suffix mean? is it reffereing to the compiled classes? the numbers I assume reffer to lines of code where the errors occur.

These files work online, but I'm trying to get them to work on my machine and to the best of knowledge there the latest ones.....

I've just been informed they aren't the latest ones, but if someone could still explain what the errors mean I be grateful for being enlightened. :D

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
Studio.navigation.InitializeComponent() in c:\inetpub\wwwroot\Studio\navigation.ascx.cs:38
Studio.navigation.OnInit(EventArgs e) in c:\inetpub\wwwroot\Studio\navigation.ascx.cs:28
System.Web.UI.Control.InitRecursive(Control namingContainer) +241
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Page.ProcessRequestMain() +174

neil
01-06-2004, 05:32 AM
I'm also getting the following error



Format of the initialization string does not conform to specification starting at index 0.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[ArgumentException: Format of the initialization string does not conform to specification starting at index 0.]
System.Data.Common.DBConnectionString.GetKeyValuePair(Char[] connectionString, Int32 currentPosition, String& key, Char[] valuebuf, Int32& vallength, Boolean& isempty) +942
System.Data.Common.DBConnectionString.ParseInternal(Char[] connectionString, UdlSupport checkForUdl, NameValuePair& keychain) +116
System.Data.Common.DBConnectionString..ctor(String connectionString, UdlSupport checkForUdl) +114
System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +13
System.Data.SqlClient.SqlConnectionString.ParseString(String connectionString) +96
System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +11
System.Data.SqlClient.SqlConnection..ctor(String connectionString) +158
DH_1.Events.Page_Load(Object sender, EventArgs e) +43
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

neil
01-07-2004, 04:08 AM
does anyone know where I can get help on this?

I'm a bit stuck.

CardboardHammer
01-07-2004, 11:36 AM
ASP.NET is rather different from old ASP...

".cs" is the extension for a C# code-behind file.
".vb" is the extension for a VB.NET code-behind file.

"Object reference not set to an instance of an object." means exactly what it says. Declaring an object reference doesn't actually give you an object, you have to assign an object to the reference (either by assigning a reference to an existing object to it or by assigning "New WhateverObject()" to it).

If you switch to using VB.NET as your language instead of C#, I can be of better help if you have more complex issues in the future, as it's what I use. The difference between the 2 is a matter of syntax, not capability.

dancolasanti
11-08-2004, 04:07 AM
I am having the same problem. The UserControl that is causing the problem works fine if I put it in the my solution's startup project. When I move it to another project within the same solution and add a reference to it in my startup solution, I get a NullReferenceException in the InitializeComponent function of my UserControl. Same problem occurs if I try to use it from another project by adding a reference to the DLL. Here is the code that's causing the problem (please note: I am aware that I am not setting imageList to a new DataList, because imageList is a control on my UserControl form and should get created by the framework):

public class ImageCollection : System.Web.UI.UserControl {
...

protected System.Web.UI.WebControls.DataList imageList;
...

private void InitializeComponent() {
// the following line produces the NullReferenceException
this.imageList.ItemCommand +=
new System.Web.UI.WebControls.DataListCommandEventHandler(this.imageList_ItemCommand);

this.Load += new System.EventHandler(this.Page_Load);
}