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

Why is my event.Subscribe() line returning a null reference error?

I am learning WPF with Caliburn Micro. I have read the documentation many times and I am even following tutorial on YouTube by Timcorey. Somewhere along the line I must have not specified/initialized something correctly. Normally I would specify the…
jeranio
  • 53
  • 8
0
votes
1 answer

How do I put a BitmapSource object into an array without it turning null outside function scope?

Simply put... private void LoadImage(object sender, EventArgs e){ String path = null; Microsoft.Win32.OpenFileDialog oFD = new ...(); if(oFD.showDialog == true){ path = oFD.FileName; result = new BitmapImage(new…
JoseAyeras
  • 75
  • 7
0
votes
0 answers

Nullreferenceexception is unhandled by user code C# (ThumbCache.db File)

I'm working on project to open Thumbscache.db files located at C:\%USERPROFILE%\AppData\Local\Microsoft\Windows\Explorer What is ThumbCache.db or Thumbs.db is? On computers running Microsoft Windows, a thumbnail cache is used to store thumbnail…
0
votes
2 answers

How can I solve this null reference error?

I have an array where the user can fill it up with objects. Objects are different sodas. There is a function in this simulator where the user has the option to find a specific soda. I don't want it to be case-sensitive so im using the method…
AllanJ
  • 147
  • 1
  • 15
0
votes
1 answer

Exception caught sending update: System.NullReferenceException: Object reference not set to an instance of an object

I added push notification handling codes to my xamarin forms UWP application. Codes: async Task InitRemoteNotificationAsync() { var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); …
Sreejith Sree
  • 3,055
  • 4
  • 36
  • 105
0
votes
3 answers

Accessing session info gives System.NullReferenceException

I'm bit new to ASP.net c# MVC. I'm trying to create a login application and create a session.In my application I have a login controller. In the login controller I read logged in user's data to session variables like in the following code segment.…
ChathurawinD
  • 756
  • 1
  • 13
  • 35
0
votes
1 answer

C# - Failed at calling another script

I've created two scripts. One includes a variable and a method. Second script's task is to call the first script and access its component. However I'm getting the following error : ThisScriptWillCallAnotherScript.Update () (at…
Mh.A
  • 11
  • 2
0
votes
1 answer

NullReference error only when not debugging in Unity 3D player

I'm working in a Unity 3D app where I have 2 methods that connects to a service by using Oauth: one retrieves the token, and the other retrieves the JSON output from the service, based on the token. Once the JSON is ready then I change the text on a…
saman0suke
  • 762
  • 1
  • 8
  • 24
0
votes
6 answers

Why does this throw a NullReferenceException?

private void alterNodeValue(string xmlFile, string parent, string node, string newVal) { XDocument xml = XDocument.Load(this.dir + xmlFile); if (xml.Element(parent).Element(node).Value != null) { …
PiZzL3
  • 2,092
  • 4
  • 22
  • 30
0
votes
0 answers

How to avoid usage of Task.Delay while scrolling to a particular point in Scroll View as I am adding children in runtime which are out of view?

Here, I have used a scroll view and children are added upto visible height and the other children are added in runtime while scrolling down. Hence I need to scrollTo a particular point like Scrollview.ScrollTo(x,y) for this I need to calculate y by…
0
votes
2 answers

C#: IBM-Watson Unity SDK NullReferenceException When Trying To Create A Session Using Watson Assistant V2

I'm trying to run the example in the IBM Watson Unity SDK but I'm getting a NullReferenceException when it tries to create a session. This is the script given as an example with the SDK with the exception of the modified lines. I added these in…
0
votes
1 answer

How to modify control properties through variable reference

I've been working on making a project of mine more modular. Something I've wanted to do is have multiple buttons use the same function when they perform a similar action, but with different values. I've been stuck on trying to apply this to the…
0
votes
1 answer

IFormFile is null value when uploading file from postman to web API

I tried to test uploading an IFormFile through postman to web API and the error shows the IFormFile is a null value. [HttpPost("upload")] public async Task Post(IFormFile photo) { try { // Full path…
0
votes
0 answers

Baffled by a simple Debug.Log(object) -> returns "object" AND "NULL"

After a couple of hours of tackling a nasty bug, I managed to break it all down to one single thing that I can't comprehend. I have a gameObject character, which has 2 component scripts. 1) StateSwitcher (a class applying the factory design…
Thrindil
  • 143
  • 3
  • 17
0
votes
2 answers

I want to understand AND (&&) run time exception

Hello everyone today I was working to make API.I got confused when I saw different behavior of C# compiler. let me explain: I get exception: If(userLoginModel.UserId>0) { //do something } else{ //do something } Exception: {"Object reference not set…
Wajid khan
  • 842
  • 9
  • 18