nullreferenceexception

Event Handler behavioral difference .net 1.1 vs 2.0 with null delegate

Not sure what exactly is going on here, but seems like in .NET 1.1 an uninitialized event delegate can run without issues, but in .NET 2.0+ it causes a NullReferencException. Any ideas why. The code below will run fine without issues in 1.1, in 2.0 it gives a NullReferenceException. I'm curious why does it behave differently? What ch...

ASP.NET application breaks when deploying to IIS

Hello everybody, I am developing a small ASP.NET website for online shopping, when testing it out in Visual Studio, everything works fine, however that is no longer the case when I deploy it to IIS. The problem seems to be in a DLL file that I reference, this DLL file contains the Classes I need to initialize and send query requests to ...

Strange nullreference exception

So I have this code that takes care of command acknowledgment from remote computers, sometimes (like once in 14 days or something) the following line throws a null reference exception: computer.ProcessCommandAcknowledgment( commandType ); What really bugs me is that I check for a null reference before it, so I have no idea whats going...

Is the IsNullOrEmpty bug fixed in .NET 3.0 or later?

Does anyone know if the IsNullOrEmpty bug is fixed in 3.0 or later? I currently came across the (NullReferenceException) bug in 2.0 and I have found documentation stating that is supposed to be fixed in the next release, but no definitive answer. ...

Using VB.NET IIF I get NullReferenceException

I am doing a little debugging, and so I want to log the eventArgs value I have a simple line that basically does: logLine = "e.Value: " + IIf(e.Value Is Nothing, "", e.Value.ToString()) The way I understand the IIF function, if the e.Value is Nothing (null) then it should return the empty string, if not it should return the .ToString...

Null Reference Exception

This code generates and Null Reference exception. Exception comes at the line where the parameter array is initialized. What can be the problem? I don't know howto follow the stack-trace and work any logic over it. thanks in advance. DAL dal = new DAL(); string SQL = @"INSERT INTO Assets ([AssetName],[AssetType],[Model],[De...

LINQ InsertOnSubmit: NullReferenceException

I have this code: using DC = MV6DataContext; using MV6; // Business Logic Layer // ... public DC.MV6DataContext dc = new DC.MV6DataContext(ConnectionString); IP ip = new IP(Request.UserHostAddress); dc.IPs.InsertOnSubmit(ip); dc.SubmitChanges(); // in Business Logic layer: public class IP : DC.IP { public IP(string address) { ... } ...

C#, Linq2SQL: Sum() causes exception instead of returning 0 when no rows

I have this code (ok, I don't, but something similar :p) var dogs = Dogs.Select(ø => new Row { Name = ø.Name, WeightOfNiceCats = ø.Owner .Cats .Where(æ => !æ.Annoying) .Sum(æ => æ.Weight), }); Here I go through all dogs and sum up the weight (into a non-null...

Silverlight control in XAML is null at runtime

I've created a silverlight app with a DeepEarth map control on it. Here is my base XAML <Grid x:Name="LayoutRoot" > <!-- Map Control --> <DeepEarth:Map x:Name="map" Margin="0,0,0,0"> <Controls:CoordControl VerticalAlignment="Bottom" HorizontalAlignment="Right" /> <Controls:ScaleControl VerticalAlignment="Bottom" HorizontalAlignmen...

Why am I getting this NullReferenceException?

Hi all, I'm working on a project that involves some home-made (de-)serialization code, and I have run into some issues with the deserializing of a List. The following code is throwing a NullReferenceException on the second line, even though the var list is not null, and happily reports Count = 0 when hovering my mouse over it. System.C...

Should NullRefs ever be caught?

I recently made the statement to a colleague that: NullReferenceExceptions should never be explicitly caught I used the word never.... hmmm. I've never seen a appropriate use case myself for catching them but I wanted to check if anyone else has? Never is such a strong word after all..... ...

ASP.Net MVC RC2 ValidationMessage and form field conflict?

I am having problems with MVC RC2 where upon validation failure, the failed field will throw a NullReferenceException when the view is passed back to the user. A short term solution was found: which was to rename the Html.ValidationMessage to be different than the Target Form Field. This works! BUT now the automatic highlighting is di...

Why am I getting a NullReferenceException from Membership.GetCurrentUserName ?

I've just switched to using msbuild to precompile my website and now I'm getting this strange error: I have a call to Membership.GetUser() which throws: [NullReferenceException: Object reference not set to an instance of an object.] System.Web.Security.Membership.GetCurrentUserName() +36 System.Web.Security.Membership.GetUser() +7 ... ...

How to avoid a NullReferenceException

if (alMethSign[z].ToString().Contains(aClass.Namespace)) Here, I load an exe or dll and check its namespace. In some dlls, there is no namespace, so aclass.namespace is not present and it's throwing a NullReferenceException. I have to just avoid it and it should continue with rest of the code. If I use try-catch, it executes the catc...

A nicer way to handle null references in a object hierarcy

I’m looking for a nice way to handle a null reference in object hierarchy. ie: if(null == Object1.Object2.Object3.Property) This example will throw a Null Reference exception if say Object2 is null. In my case I don't care what is null, just that something is. I don't really want to put try/catches around each place that I want to d...

NullReferenceException with ToolTip.CreateHandle

We sporadically get errors when we try to update a tool tip, like this ToolTip.SetToolTip(myLabel, customDataStructure) The error we get is a NullReferenceException: Object reference not set to an instance of an object Does anyone know the cause of this? Is a simple Try/Catch that eats the NullReferenceException a feasible option? ...

Why is XPathSelectElement is giving a NullReferenceException?

The following code gives a NullReferenceException since XPathSelectElement can't navigate through the XPath expression I've given: String description = (String)node.XPathSelectElement("//car").Attribute("description"); I've debugged this and verified that the node is being read correctly, and that the elements in my XPath are capitali...

NullReferenceException Error in ASP.NET with C# - Trying to Handle Error

I have a ASP.NET webform that, aside from other controls, has a textbox for entering a value, a textbox to display values, a dropdownlistbox, and a search button. I am using the following code to display search results: if (TextBox3.text == DropDownList3.Items.FindByText(TextBox3.Text).Value) { etc... } The DDL3 gets its values f...

C# object reference not set to an instance of an object.

I am getting the object reference error in just start of the method. For Ex.: 259: public ActionResult ShowAddress(FormCollection formCollection) 260: { In the above sample i am getting the error Line number 260. Please anyone can suggest me the problem with this. ...

C#: Why do I get an OutOfMemoryException on a NullReferenceException?

I got an OutOfMemoryException earlier and couldn't figure out what it was for. It made no sense at all. Dug around in my code, and suddenly remembered that somewhere had forgotten to check for null, and in this particular case it was (and should be) exactly that. That shouldn't cause an OutOfMemoryException in my opinion, but I fixed it ...