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
7
votes
2 answers

c# Xunit, Assert.Throws fails when expected exception raised

EDIT: There is a similar question here, but the solutions only suggest workarounds and provide no insights into the cause of the issue or how to fix it. This question may still be a duplicate. EDIT 2: It turns out this issue is only happening during…
Kelson Ball
  • 948
  • 1
  • 13
  • 30
7
votes
1 answer

CIL unbox_any instruction - strange behavior

.method public static void Test(object A_0) cil managed { // Code size 13 (0xd) .maxstack 1 .locals init (!!T V_0) IL_0000: ldarg.0 IL_0001: isinst !!T IL_0006: unbox.any !!T IL_000b: stloc.0 IL_000c: ret }…
Dudi Keleti
  • 2,946
  • 18
  • 33
7
votes
1 answer

NullReferenceException loading RenderWindowControl for vtk in WPF

I am trying to load a RenderWindowControl from vtk libraries on my WPF proyect using ActiViz.NET and Visual Studio 2013. The library works fine since I did a new project just to practice on itbut when I tried to integrate it into my work, I got a…
Sierra
  • 313
  • 1
  • 5
  • 17
7
votes
10 answers

Interview Question in C#

A Technical Lead asked me the following: He created a class, declared an object and initialized it. But in some circumstance we may get "null reference" exception. He commented that there are 1000 possible reasons for such exception and asked me to…
amutha
  • 87
  • 2
7
votes
1 answer

How to make a wpf MediaElement play when its Source is a https uri

In a wpf standalone application (.exe) I have included a MediaElement in the MainWindow
7
votes
4 answers

NullReferenceException was unhandled by user code - Object reference not set to instance of an object

I have the following C# classes: public class Locales { public Region region { get; set; } public Buttons buttons { get; set; } public Fields fields { get; set; } } public class Region { public Center center { get; set; } public…
anitacynax
  • 255
  • 1
  • 7
  • 14
7
votes
1 answer

F# interop with C# class that has an optional nullable parameter set to anything but null causes NullReferenceException / AccessViolationException

I have the following C# classes public class BadClass { public BadClass(int? bad = 1) { } } public class GoodClass { public GoodClass(int? good = null) { } } As you can see they both have optional nullable parameters as…
TWith2Sugars
  • 3,384
  • 2
  • 26
  • 43
7
votes
1 answer

how to get the store in a component in ember.js

How in the world do i get a handle on the store inside of a component? I'm trying to create an auto-complete component that returns results from the store. App.AutoCompleteComponent = Ember.Component.extend({ …
David
  • 10,418
  • 17
  • 72
  • 122
7
votes
1 answer

How to properly instantiate HttpContext object?

I am trying to create a simple code to retrieve a string for the current url as follows: string currentURL = HttpContext.Current.Request.Url.ToString(); However, I get the error upon running the code: Object reference not set to an instance of an…
TestK
  • 323
  • 1
  • 4
  • 14
7
votes
1 answer

How to inherit a UserControl from another UserControl?

Is it possible to inherit a User control from another user control? The thing I'm trying to achieve is a user control inheriting from another user control. So I have baseusercontrol.ascx, and this just has text "Stuff". Then I have another user…
Sudha
  • 2,078
  • 6
  • 28
  • 53
7
votes
1 answer

Object reference not set to an instance of an object. in MVC Layout = null

I'm getting a strange error located in @{ Layout = null; } This is the error : Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review…
Rafael Adel
  • 7,673
  • 25
  • 77
  • 118
7
votes
3 answers

Why is it showing NullReferenceException when the variable is not null?

Why is VS 2012 showing the Type variable as an NullReferenceException when it also shows that it's value = "Retailer". I've got a newborn, and I'm working on limited sleep, so I apologize if I'm missing something obvious here. The…
6
votes
3 answers

VB .Net NullReferenceException work-around

This should be simple, but I am having problems. Using the eBay .Net library, sometimes certain fields in a response are Nothing and sometimes contain a value. When they are Nothing they could simple be represented as an empty string, but the…
Mike L.
  • 1,936
  • 6
  • 21
  • 37
6
votes
4 answers

Why do I get this NullReferenceException C#

I've been working in some codes for an application to manage connected users and Equipments via Active directory queries. Then I get this error "NullReferenceException was unhandled" for about a week, working with the code this is the only thing…
6
votes
3 answers

Strange NullReferenceException with INotifyPropertyChanged implementation

I'm implementing INotifyPropertyChanged in a base class as follows: public class NotifyPropertyChangedBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected virtual void…
rumblefx0
  • 665
  • 1
  • 9
  • 22