FAQ Database Discussion Community


NullException no matter what I try in c# [duplicate]

c#,asp.net,session,datatable,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I have a datatable session Session["Items"] = dt; I am trying to display the count from the session in Site.Master at the top, kind of like on ecommerece websites where...

System.NullReferenceException based on List [duplicate]

c#,winforms,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I'm trying to loop through rows and get their Indexes (Primary Keys from SQL). I'm getting a NRE on "this.SelectRowIndexes.Add(ResourceKey)" I can't figure out why it would matter and how...

F# module member uninitialized

f#,nunit,nullreferenceexception,fsunit
I'm writing unit tests in F# using FsUnit and NUnit, with the NUnit test adapter for VS2015 Ultimate CTP. I've come across an odd issue with a module member being null, where I wouldn't expect it to be. Is this an issue with the the code, or the way the...

Generic function [duplicate]

c#,generics,nullreferenceexception
This question already has an answer here: How to get a property value using reflection 2 answers I'm trying to create a simple generic function: public T GetPost<T>(HttpListenerRequest request) where T : new() { Stream body = request.InputStream; Encoding encoding = request.ContentEncoding; StreamReader reader = new StreamReader(body, encoding); string...

“Object reference not set to an instance of an object” [duplicate]

c#,xna,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; //Character Texture2D character; Texture2D background; Texture2D ground; //Movement Vector2 position = Vector2.Zero; Vector2 velocity; bool hasJumped; float movespeed = 500f;...

NullReferenceException when adding to Dictionary in Asynchronous context

c#,.net,dictionary,asp.net-mvc-5,nullreferenceexception
I am having a very strange behaviour as in this picture: As you can see in the Watch window, everything that can be possibly null are not null. Here is the full code of the function: public LogInTokenCache GetUserIdFromToken(string token) { LogInTokenCache item = null; if (this.TokenCache.ContainsKey(token)) { item =...

Sybase SQL Anywhere driver throws NullReferenceException

c#,multithreading,.net-4.0,nullreferenceexception,sqlanywhere
I have the problem, that in my multithreading application, the SQL Anywhere 12 driver throws NullReferenceExceptions. The Exception is always thrown at different points, but always during opening a connection. There are a maximum of 5 open connections. The stack trace is the following: I have no idea why this...

Dependency injection using IOC (Inversion of Control)

c#,interface,dependency-injection,nullreferenceexception
I've Interface public interface IDatabase { void AddRow(string table, string value); } It's implemented on public class Database : IDatabase { public void AddRow(string table,string value) { } } Now here I'm doing Dependency Injection public class CustomerRepository { private readonly IDatabase _database; private readonly string ss; public CustomerRepository() {...

How can I overwrite a LiteralControl's text only if the LiteralControl has not already had text assigned to it?

c#,sharepoint-2010,nullreferenceexception
This code: private void btnSave_Click(object sender, EventArgs e) { LiteralControl message = null; try { message = new LiteralControl(); Controls.Add(message); ConditionallyCreateList(); SaveInputToList(); List<ListColumns> listOfListItems = ReadFromList(); GeneratePDF(listOfListItems); // using iTextSharp } catch (Exception ex) { message.Text = String.Format("Exception occurred: {0}", ex.Message); } if (message.Text.Length <= 1) { message.Text = "Saving...

MVC Winforms c# nullreferenceexception [duplicate]

c#,winforms,model-view-controller,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I am a nooby trying to learn mvc in C# winforms, but I cant seem to understand why my instance turns null on me. View Form public partial class Form1...

c# facing System.NullReferenceException [duplicate]

c#,arrays,split,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I have tried to read from text a list of integer into jagged array (because its every row contains different number of elements separated by space) but i face System.NullReferenceException...

How to pass the current instance to FieldInfo.GetValue inside the instance?

c#,nullreferenceexception,system.reflection
I'm making an abstract class that I need to validate fields in it's descendants. All the validated fields are marked by an attribute and are suppose to be checked for nulls or empty. To do that I get all the fields in the class: var fields = this.GetType().GetFields().Where(field => Attribute.IsDefined(field,...

NullReferenceException I can't seem to solve with Null Collase operator [duplicate]

c#,.net,sharepoint,sharepoint-2013,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I have a SharePoint list that I'm reading. In this list there are a number of items that don't have a value assigned to them, throwing an error. The code...

How to check string for null and assign its value in the same line

c#,asp.net,string,linq,nullreferenceexception
If I have a datatable which has a one row ,How to check the field for not null to avoid the exception and assign its value in the same line ? txt_objective.Text = dtReqMas.Rows[0]["objective"].ToString().Trim(); Now I want to check dtReqMas.Rows[0]["objective"] for null and set txt_objective.Text = String.Empty; if it was...

An unhandled exception of type 'System.NullReferenceException' occurring [duplicate]

c#,object,try-catch,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers In the following code I get the null reference error on the first line in my finally statement - invoice[x].IdNumber = idResult; how can it give me a null reference...

SignInManager.PasswordSignInAsync Throwing Null Object Exception

c#,asp.net-mvc,asp.net-mvc-5,nullreferenceexception,owin
AccountController.cs houses the AccountController class. The Login method of that class is failing. Specifically, var result = await SignInManager.PasswordSignInAsync( model.Email, model.Password, model.RememberMe, shouldLockout: true); within the Login method is throwing System.NullReferenceException. I've verified that model.Email, model.Password, and model.RememberMe are not null. The next step is to dig in to SignInManager,...

Getting NullReferenceException when trying to add a value to an array

c#,variables,windows-runtime,windows-phone-8.1,nullreferenceexception
I'm having issues with this code. Everytime when it runs, it returns me the 'System.NullReferenceException'. // Clear out the Array of code words wordBuffer = null; Int32 syntaxCount = 0; // Create the regular expression object to match against the string Regex defaultRegex = new Regex(@"\w+|[^A-Za-z0-9_ \f\t\v]", RegexOptions.IgnoreCase | RegexOptions.Singleline);...

How do I to add object collection to an object variable collection? [duplicate]

c#,asp.net,collections,nested,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I have a nested collection in side an object: public class Question { public AnswerObjectCollection Answers { get; private set; } } When I try to add answers to the...

Object created, but for some reason throwing an NRE when adding to a list [duplicate]

c#,winforms,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I have declared this list: public ObservableCollection<Order> Orders { get; set; } and then tried to create an object and add it to the list here: Order curOrder = new...

How to Safely Query for a Potentially Nonexistent Value in SQLite?

c#,sqlite,nullreferenceexception,empty-string,executescalar
I've got this code, which works as long as there is a matching value in the database: public String GetDeptNameForDeptId(int deptId) { String deptName; const string qry = "SELECT Name FROM Department WHERE Id = @deptID"; try { using (SQLiteConnection con = new SQLiteConnection(HHSUtils.GetDBConnection())) { con.Open(); SQLiteCommand cmd = new...

Getting Error object reference not set to an instance of the object [duplicate]

c#,.net,winforms,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I'm creating windows form speech recolonization application but somehow not able to fix the object reference issue: Can anyone please tell where I'm going wrong, as I'm getting Getting Error...

NullReferenceException was unhandles using Windows Forms c#

c#,null,nullreferenceexception
I am getting the exception NullReferenceException was unhandled I have tried and tried again to solve this but hours later and I'm coming here for help. This is where I'm getting the error: Form1 objectForm1 = new Form1(); for (int i = 0; i < 1; i++) { objectForm1.taskBox.Items.Add( objectForm1.taskItems[i].TaskName...

ASP.NET MVC application throwing system.nullreferenceexception - modelbinding to list [duplicate]

c#,asp.net,asp.net-mvc,nullreferenceexception,model-binding
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I have an asp.net application that has an index view that users can modify and save. However, when I click the save button I get the error: Object reference not...

System.NullReferenceException when trying to read registry key VisualBasic [duplicate]

vb.net,nullreferenceexception,vs-2015-preview
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I'm trying to make the checkbox filled when Launcher_SessionLoginAnimation_OnShow is set to 1. I can't seem to fix a problem which is causing a System.NullReferenceException. I tried searching google and...

Passing List from controller to View ASP.NET (null reference) [duplicate]

c#,asp.net,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I have a class. In this class I want to list the names of my .txt files in a folder and save them to List<string>: using System; using System.Collections.Generic; using...

NullReferenceException when Assigning String to ViewModel [duplicate]

c#,asp.net-mvc,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I'm experiencing the error NullReferenceException was unhandled by user code followed by Object reference not set to an instance of an object. I've read a number of questions including the...

Populating an array with values from list check boxes [duplicate]

c#,asp.net,arrays,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I am trying to populate an array with values from check boxes. I am using list check boxes. I spent hours to find the error. I am getting NullReferenceException was...

ArrayList.AddRange is not allowing to add another array

vb.net,arraylist,nullreferenceexception
While I'm trying to add an arrayList2 to Another ArraList1 (ArraList1 is Nothing) through AddRange Method, it is throwing: NUllUnhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object Private Sub Fun1(ByVal ArrayList2 As ArrayList) Dim ArraList1 As ArrayList = ViewState("Details") ArraList1.AddRange(ArrayList2 ) Please let me know...

Function to write cells in excel

c#,excel,nullreferenceexception
I get a bit of code from here: http://forum.codecall.net/topic/71788-reading-excel-files-in-c/ which works fine and is easy to understand for me. It can only read excel cells tho, and I want to write some too. So I want to do this in my main: excel_setValue("C10", "520"); This is what I tried as...

System.NullReferenceException with registry edit in Vb.net

.net,vb.net,internationalization,registry,nullreferenceexception
i have a problem with changing a registry value. i want to set the decimal symbol from "." to "," bud everytime i debug it, it gives a System.NullReferenceException i do partly understand what it means bud i just dont know how to fix the problem. i am using visual...

Seting value of a property for an item causes NullReferenceException

c#,nullreferenceexception
Basically what I am trying to do is add a customer in a customer list, in the customer list there is a property BillToContact. I would like to create an instance BillToContact for a customer. public class Customer { public string ID { get; set; } public string AccountName {...

EF6 proxy's reference is sometimes null when entity's IValidatableObject.Validate method is called

entity-framework,entity-framework-6,nullreferenceexception
An EF6 proxy has a reference that is sometimes null when my entity's IValidatableObject.Validate method is called by the DbContext's SaveChangesAsync method. Running the same exact code multiple times results in different behavior. If I check my stock's Sku property (i.e. stock.Sku == null) outside of the Validate method it...

Problems with ArgumentNullException

c#,asp.net,nullreferenceexception
I have a variable of type List<Foo> declared on the top of my C# class in my ASP.NET project. In the load method I instanciate this class, but when I try to use this object (already instanciated in load method) in another method it is null, giving me the error...

NullReferenceException in VS2013 when breakpoints hit in Xamarin.Android

c#,android,visual-studio-2013,xamarin,nullreferenceexception
After updating Xamarin.Android for Visual Studio to the latest stable version, I get a strange error. When launching the application in debug mode, Visual Studio will sometimes throw a NullReferenceException where it is not expected. This happens at the line ThreadPool.QueueUserWorkItem(x => ContinueOnCreate()); in my Activity's OnCreate method. The strange...

How to resolve System.NullReferenceException: Object reference not set to an instance of an object in xamarin android

android,file,xamarin,monodroid,nullreferenceexception
I am facing this issue in this code line - File videofiles=new File(App._file.AbsolutePath); guys please help me out ths issue .thanks in advance. Exception Log System.NullReferenceException: Object reference not set to an instance of an object at VRecorder.MainActivity.deleteVideo () [0x00001] in e:\workspace\VRecorder\VRecorder\MainActivity.cs:91 at VRecorder.MainActivity.<OnCreate>b__1 (object,System.EventArgs) [0x00001] in e:\workspace\VRecorder\VRecorder\MainActivity.cs:49 at Android.Views.View/IOnClickListenerImplementor.OnClick...

NullReferenceException location information? [duplicate]

c#,nullreferenceexception
This question already has an answer here: Display lines number in Stack Trace for .NET assembly in Release mode 6 answers I have an application (released) and a NullReferenceException that is popping up for users VERY rarely, yet I want to take care of it. I've looked over the...

Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment

c#,design-patterns,compiler-errors,hashtable,nullreferenceexception
In my internal Game class, I have both a) defined another nested internal GamerTags class and b) defined a GamerTags[] _array variable. In my internal GamerTags class (the nested class, for simplicity I left it out) I have a readonly Hashtable. After initialization, I still get a null ref exception...

Null reference exception when trying to open a workbook, vb.net

vb.net,excel,nullreferenceexception
I've got an openfiledialog reading a spreadsheet file name from a textbox, then performing some formatting and spitting out a text file. The code works fine one time through; my next task is to get it so that I can open successive spreadsheets (one at a time) without closing the...

A Nullreferenceexception was unhandledby user code. Object Reference not set to an instance of an object [duplicate]

c#,datagridview,nullreferenceexception
This question already has an answer here: What is a NullReferenceException and how do I fix it? 17 answers I have a column fields with different names. For example I load the files from ABC. and the Name column fields will be ABC. I have to show a button...