nullreferenceexception

Interaction between two user controls

I'm on the verge of madness ... In the application I'm actually building, I'm dealing with two dynamically-added controls that need to interact with each other, but I've reduced the problem to an as-simple-as-I-can-make-it example with the controls being statically loaded, and it still presents the same problem: a NullReferenceException...

When would SqlCommand.ExecuteReader() return null?

When using calling the SqlCommand.ExecuteReader() method, ReSharper tells me I have a possible NullReference exception when I use the SqlDataReader object afterwards. So with the following code: using (SqlConnection connection = GetConnection()) { using (SqlCommand cmd = connection.CreateCommand()) { cmd.CommandText = ;...

How to debug a low level system exception in Visual Studio 2003?

Hello, I have spend two days of work trying to figure out a weird problem is happening on my PC. I am debugging a quite complex old application written in .NET 1.1 that is made by an mdi container that load at runtime different assemblies that implements custom interface as windows form mdi child. The problem is that on my PC (i tried...

Is there a tool that can check for null reference exceptions?

Is there a tool available that can scan code and check for possible null reference exceptions, i.e. where there is no code to check for null before calling a method / accessing a property? ...

C# - Calling a method from within a Class

I have 2 Forms (Form1 and Form2) and a class (Class1). Form1 contains a button (Button1) and Form2 contains a RichTextBox (textBox1) When I press Button1 on Form1, I want the method (DoSomethingWithText) to be called. I keep getting "NullReferenceException - Object reference not set to an instance of an object". Here is a code example:...

NullReferenceException Controls.Add c# error

I'm getting the following error after I start debugging my program. Do you know how to fix this? System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object." It is referring to the line: pnlDropDownList.Controls.Add(ddl); inside the CreateDropDownLists method. Apparently...

Why couldn't I check for a null reference on a connection string?

Probably a C# noob question, so don't flame me. I was trying to do this: if (ConfigurationManager.ConnectionStrings["PrimaryConnectionString"].ConnectionString != null) { // ... } But I kept getting a System.NullReferenceException. I thought since it returns a string that I could just check for null and move on. It took me a while...

I'm Trying to Create an Image Object with a Byte Array as Its Source. What Am I Doing Wrong?

I'm trying to create an image object with a byte array as its source. What am I doing wrong? An exception is thrown when I try to initialize the image object with an array of bytes as source data. The exception is shown in my code, below. public class MyClass { publuc System.Windows.Media.Imaging.BitmapImage InstanceImage { get...

NullReferenceException when accessing a property outside of the constructor

In this class, I am setting elp to ElType in the constructor. I can access properties of elp fine when in the constructor (the // ... bit is where I'm accessing elp's properties), but when I try to access elp in another method - ucp() - my program crashes with NullReferenceException. I can't figure out what I'm doing wrong here, althou...

Null Reference Exception In LINQ to SQL DataContext

I have a Null Reference Exception Caused by this code: var recentOrderers = (from p in db.CMS where p.ODR_DATE > DateTime.Today - new TimeSpan(60, 0, 0, 0) select p.SOLDNUM).Distinct(); result = (from p in db.CMS where p.ORDER_ST2 == "SH" && p.ODR_DATE > DateTime.Today - new TimeSp...

How did I get this NullReferenceException error here right after the constructor?

I've had an asp.net website running live on our intranet for a couple of weeks now. I just got an email from my application_error emailer method with an unhandled exception. Here it is (ive cleaned up some of the paths to make it better displayed) Exception : Object reference not set to an instance of an object. Stack Trace : at ...

NullReference Exception in VB.NET for an Integer

Here's the troublesome bit of code. Note that the NullReference Exception is throw for the variable TR, but PS is just fine. Any idea what could be happeneing? Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) ''// set up the controls Dim PS As Integer Dim TR As I...

Nhibernate NullReferenceException returning List of domain objects

Following is the code I am using. Seems pretty simple to me. But I get a NullReferenceException at the last line , the return statement. Here is the stack trace: FailedSystem.NullReferenceException: Object reference not set to an instance of an object. at NHibernate.Criterion.Junction.ToSqlString(ICriteria criteria, ICriteria...

Visual Studio null reference warning - why no error?

I've noticed something peculiar about Visual Studio. First, try typing this (C#) somewhere in a function: class Foo { public void Bar() { string s; int i = s.Length; } } Now, right away it will mark the s in s.Length as an error, saying "Use of unassigned local variable 's'". On the other hand, try ...

Is it possible to get a null reference error from the ListBox.Items property?

EDIT 11-20-2009: This question was posted quite some time ago, but the problem just crept up again this morning; so I'm hoping somebody else can provide some insight (though the answers provided already have been helpful). Once in a blue moon in our production environment we get a NullReferenceException from referencing the Items proper...

Get Object reference when using context rewrite path

Hello I get this error when i have this in my codebehind: if(Page.User.Identity.IsAuthenticated) System.NullReferenceException: Object reference not set to an instance of an object. This error show when i use context.RewritePath method http://localhost/page.apsx?id=22 --> http://localhost/hello-world/ Page.User.Identity.IsAuthenti...

assembly in deployed asp.net application is referencing an absolute path on my pc

I do not know why this is happening: [NullReferenceException: Object reference not set to an instance of an object.] DataWeb.Core.HttpHandler.ProcessRequest(HttpContext Context) in X:\projects\visualstudio\work_projects\Production\DataWeb\DataWeb.Core\HttpHandler.cs:23 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication...

Why does a GetType on a string-property result in a NullReferenceException ?

When I call a GetType on a int- or a DateTime-property, I get the expected results, but on a string-property, I get a NullReferenceException (?) : private int PropInt { get; set; } private DateTime PropDate { get; set; } private string propString { get; set; } WriteLine(PropInt.GetType().ToString()); // Result : Syst...

NullReferenceException when calling InsertOnSubmit in Linq to Sql.

I'm trying to insert a new object into my database using LINQ to SQL but get a NullReferenceException when I call InsertOnSubmit() in the code snippet below. I'm passing in a derived class called FileUploadAudit, and all properties on the object are set. public void Save(Audit audit) { try { using (ULNDat...

vb.net: "Object reference not set to an instance of an object" when creating user structre

Hi! I get an "Object reference not set to an instance of an object" error while running this code below, and I don't know what is wrong with it.. goes like this: Dim mypoint As New PairOfSingle(0, 0) Private Structure PairOfSingle Dim x As Single Dim y As Single Public Sub New(ByVal xCoordinate As Single, ByVal y...