193 questions
1864
votes
26
answers
2.5m
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?
270
votes
8
answers
2.4m
views
What does "Object reference not set to an instance of an object" mean? [duplicate]
I am receiving this error and I'm not sure what it means?
Object reference not set to an instance of an object.
55
votes
3
answers
71k
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,...
220
votes
22
answers
702k
views
Value cannot be null. Parameter name: source
This is probably the biggest waste of time problem I have spent hours on solving for a long time.
var db = new hublisherEntities();
establishment_brands est = new establishment_brands();
est....
127
votes
20
answers
191k
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 ...
324
votes
22
answers
1.4m
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 ...
27
votes
18
answers
40k
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 ...
24
votes
5
answers
6k
views
Initializing list property without "new List" causes NullReferenceException
using System;
using System.Collections.Generic;
class Parent
{
public Child Child { get; set; }
}
class Child
{
public List<string> Strings { get; set; }
}
static class Program
{
...
44
votes
5
answers
67k
views
httpcontext.current.server.mappath Object reference not set to an instance of an object
I am using the following code within a class:
string filePath = HttpContext.Current.Server.MapPath("~/email/teste.html");
The file teste.html is in the folder
But when it will open the file the ...
29
votes
7
answers
54k
views
findViewById returns NULL when using Fragment
I'm new to Android developing and of course on Fragments.
I want to access the controls of my fragment in main activity but 'findViewById' returns null.
without fragment the code works fine.
Here's ...
12
votes
5
answers
13k
views
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:
...
63
votes
6
answers
35k
views
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 (I've cleaned ...
49
votes
3
answers
25k
views
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 ...
33
votes
3
answers
154k
views
Error checking for NULL in VBScript, getting "Object Required"
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 ' ...
23
votes
4
answers
3k
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:
/...