nullreferenceexception

“Object reference not set to an instance of an object” when building my cloud project

做~自己de王妃 提交于 2019-11-30 03:13:11
When I build my solution with a bunch of cloud projects, I see one or more "Error: Object reference not set to an instance of an object" messages in the output. When I try to run one of the cloud projects, I get the popup "There were build errors. Do you want to continue and run the last successful build", but there are no errors in the Error List and the same "Error: Object ref..." errors in the output. When I click package on my cloud project I get a messagebox with "Object reference not set to an instance of an object", also when I right click -> properties on the project reference under

Checking session if empty or not

痞子三分冷 提交于 2019-11-30 03:00:41
I want to check that session is null or empty i.e. some thing like this: if(Session["emp_num"] != null) { if (!string.IsNullOrEmpty(Session["emp_num"].ToString())) { //The code } } Or just if(Session["emp_num"] != null) { // The code } because sometimes when i check only with: if (!string.IsNullOrEmpty(Session["emp_num"].ToString())) { //The code } I face the following exception: Null Reference exception Use this if the session variable emp_num will store a string: if (!string.IsNullOrEmpty(Session["emp_num"] as string)) { //The code } If it doesn't store a string, but some other type, you

Why is [Owin] throwing a null exception on new project?

允我心安 提交于 2019-11-30 01:11:58
I have a rather strange issue i'm not sure how to fix or if i can even fix it. I've done some research into the issue but can't find an answer to what's causing it. I'm following a rather simple guide at http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on and after enabling SSL and changing the controller to require https i get the following error: Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request.

Why does Entity Framework return null List<> instead of empty ones?

ぃ、小莉子 提交于 2019-11-30 00:13:41
问题 I'm pretty new in the ASP .NET MVC world. Maybe, that's the reason I can't explain to myself the cause of what is, for me, an annoying problem. I have one class with One-To-Many relashionship. class MyClass{ public List<OtherClass> otherClasses {get;set;} } When I'm persisting one instance of this class, I fill it's relationship with an empty List<> MyClass myClass = new MyClass(){ otherClasses = new List<OtherClass>() } context.myClass.Add(myClass); The problem is that, when I try to

How to solve Object reference not set to an instance of an object.? [duplicate]

霸气de小男生 提交于 2019-11-30 00:06:37
问题 This question already has answers here : What is a NullReferenceException, and how do I fix it? (31 answers) Closed 6 years ago . In my asp.net program.I set one protected list.And i add a value in list.But it shows Object reference not set to an instance of an object error protected List<string> list; protected void Page_Load(object sender, EventArgs e) { list.Add("hai"); } How to solve this error? 回答1: You need to initialize the list first: protected List<string> list = new List<string>();

Why would finding a type's initializer throw a NullReferenceException?

牧云@^-^@ 提交于 2019-11-29 18:55:29
This has got me stumped. I was trying to optimize some tests for Noda Time, where we have some type initializer checking. I thought I'd find out whether a type has a type initializer (static constructor or static variables with initializers) before loading everything into a new AppDomain . To my surprise, a small test of this threw NullReferenceException - despite there being no null values in my code. It only throws the exception when compiled with no debug information. Here's a short but complete program to demonstrate the problem: using System; class Test { static Test() {} static void Main

Fully-qualified property name

对着背影说爱祢 提交于 2019-11-29 17:33:18
I'm trying to prevent System.NullReferenceException. I have a Company, which has a collection of Employees. Each Employee has a collection of Skills. SelectedEmployee points to the currently selected element within the Employee collection. SelectedSkill points to the currently selected element within the collection of Skills. I have a ListView that has its ItemSource bound to the Skills collection; The ListView's SelectedItem is bound to the SelectedSkill. When a Skill is deleted I want the ListView to scroll to the last element. private void DeleteSelectedSkillFromSelectedEmployee() { Company

EmguCV - Face Recognition - 'Object reference not set' exception when using training set from Microsoft Access Database

给你一囗甜甜゛ 提交于 2019-11-29 12:21:01
I've been developing a face recognition application using EmguCV (C#). I got the whole thing working okay if I store the face images (training set) in simple windows folder. But, after I tried to migrate the face images to be stored in a Microsoft Access database, an 'object reference not set to an instance of an object' exception message often occurs (not always, but most of the time) when the application tries to recognize a face from the video feed. Funny thing is, the recognition actually still works okay if the exception happens to not occur. Here is the snippet of the code of my program,

How can a readonly static field be null?

不打扰是莪最后的温柔 提交于 2019-11-29 10:50:21
问题 So here's an excerpt from one of my classes: [ThreadStatic] readonly static private AccountManager _instance = new AccountManager(); private AccountManager() { } static public AccountManager Instance { get { return _instance; } } As you can see, it's a singleton-per-thread - i.e. the instance is marked with the ThreadStatic attribute. The instance is also instantiated as part of static construction. So that being the case, how is it possible that I'm getting a NullReferenceException in my ASP

Null Reference Exception when calling an Object Array

耗尽温柔 提交于 2019-11-29 08:59:38
I tried to get some help earlier and I don't think I provided enough information though I appreciate all the advice. The goal is simply to add a new instance of the Object Room to an array and print to a list box. When a user attempts to enter a room name that is already in existence it should simply display in the specs for the room that is already in the array. I keep getting a null reference exception. Here is my code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System