All Questions

1882
votes
33answers
841303 views

What is a NullReferenceException, and how do I fix it?

I have some code and when it executes, it throws a NullReferenceException, saying: Object reference not set to an instance of an object. What does this mean, and what can I do to fix this error?...
115
votes
8answers
807729 views

What does "Object reference not set to an instance of an object" mean?

I am receiving this error and I'm not sure what it means? Object reference not set to an instance of an object.
63
votes
21answers
47603 views

C# elegant way to check if a property's property is null

In C#, say that you want to pull a value off of PropertyC in this example and ObjectA, PropertyA and PropertyB can all be null. ObjectA.PropertyA.PropertyB.PropertyC How can I get PropertyC safely w...
19
votes
15answers
22509 views

avoiding null reference exceptions

Apparently the vast majority of errors in code are null reference exceptions. Are there any general techniques to avoid encountering null reference errors? Unless I am mistaken, I am aware that in la...
19
votes
2answers
31309 views

How to use global var across files in a package?

I have the following file structure: models/db.go type DB struct { *sql.DB } var db *DB func init() { dbinfo := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", DB_USER...
138
votes
10answers
534542 views

Checking if an object is null in C#

I would like to prevent further processing on an object if it is null. In the following code I check if the object is null by either: if (!data.Equals(null)) and if (data != null) However, I re...
8
votes
3answers
23445 views

Consuming JSON in WCF service method

In a larger project I am having trouble getting a WCF service method to consume a JSON parameter. So I produced a smaller test case and the behaviour is echoed. If I debug the service I can see the pa...
23
votes
4answers
2515 views

Why does this extension method throw a NullReferenceException in VB.NET?

From previous experience I had been under the impression that it's perfectly legal (though perhaps not advisable) to call extension methods on a null instance. So in C#, this code compiles and runs: ...
21
votes
3answers
94696 views

Error checking for NULL in VBScript

I have the following VBScript in a Classic ASP page: function getMagicLink(fromWhere, provider) dim url url = "magic.asp?fromwhere=" & fromWhere If Not provider is Nothing Then ' Err...
15
votes
6answers
5779 views

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);...

Previous Next