nullreferenceexception

GetHashCode on null fields?

一曲冷凌霜 提交于 2019-12-04 22:35:40
How do I deal with null fields in GetHashCode function? Module Module1 Sub Main() Dim c As New Contact Dim hash = c.GetHashCode End Sub Public Class Contact : Implements IEquatable(Of Contact) Public Name As String Public Address As String Public Overloads Function Equals(ByVal other As Contact) As Boolean _ Implements System.IEquatable(Of Contact).Equals Return Name = other.Name AndAlso Address = other.Address End Function Public Overrides Function Equals(ByVal obj As Object) As Boolean If ReferenceEquals(Me, obj) Then Return True If TypeOf obj Is Contact Then Return Equals(DirectCast(obj,

What is a NullReferenceException, and how do I fix it?

♀尐吖头ヾ 提交于 2019-12-04 19:20:24
This post is a Community Wiki . Edit existing answers to improve this post. It is not currently accepting new answers. I have some code and when it executes, it throws a NullReferenceException , saying: Object reference not set to an instance of an object. What does this mean, and what can I do to fix this error? John Saunders What is the cause? Bottom Line You are trying to use something that is null (or Nothing in VB.NET). This means you either set it to null , or you never set it to anything at all. Like anything else, null gets passed around. If it is null in method "A", it could be that

C# error System.NullReferenceException

≡放荡痞女 提交于 2019-12-04 06:12:40
问题 I have some problems with System.NullReferenceException. When server do things and we first check user is not null and then he disconnect and server progress something and it try get user comes System.NullReferenceException. I have over 20 000 lines code so i need something small not like allways check is it null.. My server is multithread so sockets get connections and disconnects users alltime on backround so thats why this comes.. I want stop that progress when user disconnect. If i put

NullReferenceException when running published website in IIS

大憨熊 提交于 2019-12-04 05:47:04
问题 I have a website that I published before adding it in IIS. After that I set the published website as the default website in IIS. I got an error that the "Object reference is not set to the instance of an object" when I inserted values through form. There is no issues when the website is running in IIS without publishing. The error occurs when values are inserted using datagrid. The error messages is as follows: Server Error in '/' Application. Object reference not set to an instance of an

get all table values from firebase null object reference firebase database [duplicate]

老子叫甜甜 提交于 2019-12-04 05:03:00
问题 This question already has an answer here : getContactsFromFirebase() method return an empty list (1 answer) Closed last year . public class ShowBPGraphActivity extends AppCompatActivity { public GraphView graphView; public LineGraphSeries <DataPoint>lineGraphSeries; public String systolicbp; public String diastolicbp; public String timebp; public String datebp; public DatabaseReference db; public BPFragmentTable bpFragmentTable = new BPFragmentTable( ); @Override protected void onCreate

Object reference not set to an instance of an object

孤者浪人 提交于 2019-12-04 03:28:07
问题 I have a class Cell: public class Cell { public enum cellState { WATER, SCAN, SHIPUNIT, SHOT, HIT } public Cell() { currentCell = cellState.WATER; MessageBox.Show(currentCell.ToString()); } public cellState currentCell { get; set; } } I then try to use it in the following class: public class NietzscheBattleshipsGameModel { private byte MAXCOL = 10; private byte MAXROW = 10; public Cell[,] HomeArray; private Cell[,] AwayArray; public NietzscheBattleshipsGameModel() { HomeArray = new Cell

NullReferenceException during object initialization [duplicate]

南笙酒味 提交于 2019-12-04 02:19:35
问题 This question already has answers here : What is a NullReferenceException, and how do I fix it? (29 answers) Closed 4 years ago . Why there's a NullReferenceException when trying to set value of X in the code below? It works fine when I use new keyword when initializing B , but why it compiles fine without new and then fails during runtime? https://dotnetfiddle.net/YNvPog public class A { public _B B; public class _B { public int X; } } public class Program { public static void Main() { var a

MySQL with Entity Framework - what am I doing wrong?

早过忘川 提交于 2019-12-04 01:07:32
问题 I am completely new to Entity Framework and even ADO.NET in general (don't typically do much work with databases). I downloaded and installed MySQL Connector/NET 6.3.5. I created a new C# project in Visual Studio 2010. I added a new ADO.NET Entity Data Model to my project and chose "Generate from database." I added a new connection to my local MySQL server w/ server name "localhost" + my user name and password. I checked all of the tables from my MySQL database to generate objects for. I

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

折月煮酒 提交于 2019-12-03 18:55:20
问题 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

c# code seems to get optimized in an invalid way such that an object value becomes null

蹲街弑〆低调 提交于 2019-12-03 11:36:16
问题 I have the following code that exhibits a strange problem: var all = new FeatureService().FindAll(); System.Diagnostics.Debug.Assert(all != null, "FindAll must not return null"); System.Diagnostics.Debug.WriteLine(all.ToString()); // throws NullReferenceException The signature of the FindAll method is: public List<FeatureModel> FindAll() Stepping through the code I have confirmed that the return value from FindAll is not null, and as you can see from the Assert, the "all" variable is not null