Questions tagged [nullreferenceexception]

The .NET exception that is thrown when there is an attempt to reference (or use) a null or uninitialized object.

A NullReferenceException occurs when you try to reference an object in your code that does not exist. For example, you may have tried to use an object without using the New keyword first, or tried to use an object whose value is set to null (Nothing in Visual Basic).

Troubleshooting Exceptions: System.NullReferenceException

Also, see "What is a NullReferenceException in .NET and how do I fix it?" for some hints.

2780 questions
0
votes
1 answer

How to fix the "object reference is not set to an instance of an object" in VB.net while parisng XML Responce text into HTMLDoc.body.innerHTML

I'm trying to load the XML response text into an HTML object in windows forms application using visual studio, but its throwing an error object reference is not set to an instance of an object Private Sub Button1_Click(sender As Object, e As…
Sandeep
  • 19
  • 4
0
votes
1 answer

NullReferenceException when accessing to an element of array from another script

I have two objects: Tile and TileGrid which have their own scripts. TileGrid can generate a 2d array of Tiles. Then I am trying to attach every Tile around the Tile in the script for every Tile, so all of my Tiles will have a reference to their…
0
votes
2 answers

Need to check for null on something that throws exception

_sponsorOrBankFacingBorrowerCompanyWizardData = CompanyData.GetCompanyWizardData(SponsorOrBankFacingBorrowerCompany.CompanyID); So the problem here is that the code tries to go into this statement no matter what, I want it to only go if it CAN go,…
slandau
  • 23,528
  • 42
  • 122
  • 184
0
votes
1 answer

Multiple NSubstitute call configurations on method accessing different properties on a reference type parameter (to avoid NullReferenceException)

I have the following test code using NSubstitute: [TestMethod] public void Test() { var foo = Substitute.For(); foo.Foo(Arg.Is(b => !b.X)).Returns(0); // Line 1 foo.Foo(Arg.Is(b => b.X)).Returns(1); // Line 2 } public…
Neo
  • 4,145
  • 6
  • 53
  • 76
0
votes
1 answer

How to FindControl on content page from dynamic User Control

I am getting a null reference exception when trying to FindControl on a button. I have a shopping cart setup where I have a content page (.aspx) based on a master page. On the content page, there is a placeholder control in which I am dynamically…
0
votes
0 answers

Inherited LINQ to SQL class throws NullReferenceException on InsertOnSubmit

In my datacontext, CalcinerDataContext, I have a class, MainData, and a simply inherited class, NewSample (used just to explore this error). The code below runs without any errors: Dim cdc As New CalcinerDataAccess.CalcinerDataContext …
blueshift
  • 831
  • 2
  • 12
  • 24
0
votes
0 answers

management problem of a NullReferenceException

I have an issue in the Try Catch block of my code below. In function SetUser, I use the getId function that returns an Id if the user exists in DB otherwise, I get a NullReferenceException. I call this function in the try catch block in Login. I…
kst92
  • 35
  • 1
  • 1
  • 8
0
votes
1 answer

I'm getting a null reference exception when Dapper tries to read a null database field. What to do?

I'm using C#.Net and the latest version of Dapper. I just started getting a null reference exception when Dapper reads a record from the database, but the field that it's trying to retrieve is null. What can I do about it? What follows is what I…
Barry Dysert
  • 665
  • 1
  • 9
  • 21
0
votes
1 answer

Alert Dialogue null object reference

I have an alertDialogue popup when a user wants to create a game, and it asks the user how many points they would like to gamble in the game, but it keeps throwing a null reference error and I am not too sure why. This is my alertDialogue positive…
brent
  • 131
  • 12
0
votes
1 answer

Can't set a date time in one of my entity framework objects, says NullReferenceException

I have a ChatSequence entity with a DateTimeCreated property that's a DateTime. But when I try and set it, I get an exception that's saying nullreferenceexception I'm setting it like this ChatSequence newSequence = new…
chuckd
  • 13,460
  • 29
  • 152
  • 331
0
votes
0 answers

Object reference not set to an instance of an object. - Sorry I just cannot understand others who posted similar

relatively new to programming and have researched this but cannot resolve my problem. Feeling a little dumb already so go easy on me... using (SqlDataAdapter da = new SqlDataAdapter(sqlcmd)) { DataTable dt…
Bukester
  • 23
  • 6
0
votes
4 answers

How to handle this exception in a cleaner way?

I've been trying to enumerate through a properties of a class and getting their values in a List of strings. But i faced a problem where i get a NullReferenceException when the value is null from the properties I Managed to Fix that by that…
Omar Alaa
  • 141
  • 2
  • 13
0
votes
2 answers

VB.net Class Object reference not set to an instance of an object

I know that this question has been asked many times before, but I just can't work it out after reading all the responses. I have no clue what I'm doing wrong and looking at it for 2 days now. I have a nested class and just trying to assign values to…
user9671207
  • 33
  • 2
  • 8
0
votes
0 answers

Successfull build but runtime error on Web Application converted from Website Project

I am trying to convert a big website project to a web application project. The project was fine as website project but after i converted it into a web application project it started to give "Object reference not set to an instance of an object." I…
0
votes
1 answer

databaseSnapshot null reference

I am using dataSnapshot to get a value from my Firebase Database, but I keep getting a null reference error. The path to my firebase is correct and I have Datasnapshot defined, so I am not too sure why this error is coming up. Here is the snippit…
brent
  • 131
  • 12