nullreferenceexception

ASP.NET application throws System.NullReferenceException from Session.Remove implementation

前提是你 提交于 2019-12-07 04:02:51
问题 We are getting random System.NullReferenceException in our ASP.NET web application. We are using inproc session state. Stacktrace: System.NullReferenceException: Object reference not set to an instance of an object. at System.Collections.Specialized.NameObjectCollectionBase.BaseRemove(String name) at System.Web.SessionState.SessionStateItemCollection.Remove(String name) at System.Web.SessionState.HttpSessionStateContainer.Remove(String name) at System.Web.UI.SessionPageStatePersister.Save()

I seem to have fallen into some massive, massive trouble with NullReferenceExceptions

久未见 提交于 2019-12-07 01:50:19
问题 Recently I'm developing a software that parses and displays XML information from a website. Simple enough right? I'm getting LOADS of NullReferenceExceptions. For example, this method: private void SetUserFriends(List<Friend> list) { int x = 40; int y = 3; if (list != null) { foreach (Friend friend in list) { FriendControl control = new FriendControl(); control.ID = friend.ID; control.URL = friend.URL; control.SetID(friend.ID); control.SetName(friend.Name); control.SetImage(friend.Photo);

Why don't object reference error exceptions in .net tell me which object was null?

戏子无情 提交于 2019-12-06 19:13:57
问题 Maybe asking the question betrays my lack of knowledge about the process, but then again, there's no better reason to ask! Tracking these down can be frustrating because stack traces can help me know where to start looking but not which object was null. What is going on under the hood here? Is it because the variable names aren't bundled in the executable? 回答1: .NET code built with full optimizations and no debug info: your local variable names are gone, some local variables may have been

C# Error with null-conditional operator and await

时间秒杀一切 提交于 2019-12-06 19:04:53
问题 I'm experiencing an interesting System.NullReferenceException whilst using the new null-conditional operator in C#. The following code gives me a NullReferenceException if "MyObject" is null: await this.MyObject?.MyMethod() I would've expected that the call to "MyMethod" would simply not be made if "MyObject" is null, or am I misunderstanding the purpose of the null-conditional operator? 回答1: You can add ?? Operator so if ?. returns null task use CompletedTask instead. await (this.MyObject?

Cast null value to a type

你离开我真会死。 提交于 2019-12-06 17:21:57
问题 I have a simple question. if we cast some null variable to a type. I expect compiler to throw Some Exception, but it is not. And I realy want to know the reason why. I mean string sample1 = null as string; string sample2 = (string)null; object t1 = null; TestClass t2 = (TestClass)t1; maybe in the first one, as operator handles the exception handling. But others samples must throw exception. How compiler handles these situations , maybe since the variables are null , it does not perform cast

GetHashCode on null fields?

谁说胖子不能爱 提交于 2019-12-06 17:01:13
问题 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

How to avoid a NullReferenceException

萝らか妹 提交于 2019-12-06 15:52:11
if (alMethSign[z].ToString().Contains(aClass.Namespace)) Here, I load an exe or dll and check its namespace. In some dlls, there is no namespace, so aclass.namespace is not present and it's throwing a NullReferenceException . I have to just avoid it and it should continue with rest of the code. If I use try-catch, it executes the catch part; I want it to continue with the rest of the code. Is aClass a Type instance? If so - just check it for null: if (aClass != null && alMethSign[z].ToString().Contains(aClass.Namespace)) Don't catch the exception. Instead, defend against it: string nmspace =

the accounts-github package is causing my meteor user to have a null email

血红的双手。 提交于 2019-12-06 12:59:04
I've added accounts-github to my meteor app, but when I try to access Meteor.user.services.github.email all i get is null. Even though I know the email is set in my github account. What am I doing wrong? The field is there, seems like accounts-github should just fetch the email for me... From the github api docs: Note: The returned email is the user’s publicly visible email address (or null if the user has not specified a public email address in their profile). To get the private email address you need to add the user:email scope to your app. If you're using accounts-ui its just Client side

How to get interpolated message in NHibernate.Validator

折月煮酒 提交于 2019-12-06 09:43:46
I'm trying to integrate NHibernate.Validator with ASP.NET MVC client side validations, and the only problem I found is that I simply can't convert the non-interpolated message to a human-readable one. I thought this would be an easy task, but turned out to be the hardest part of the client-side validation. The main problem is that because it's not server-side, I actually only need the validation attributes that are being used, and I don't actually have an instance or anything else at hand. Here are some excerpts from what I've been already trying: // Get the the default Message Interpolator

NullReferenceException when page Loads

妖精的绣舞 提交于 2019-12-06 09:31:48
I load a list from a SQLite database when my page loads and sometimes when it loads I get NullReferenceException with the error saying Object reference not set to an instance of an object. it breaks in this code in the SQLite class file public TableMapping GetMapping (Type type) { if (_mappings == null) { _mappings = new Dictionary<string, TableMapping> (); } TableMapping map; if (!_mappings.TryGetValue (type.FullName, out map)) { map = new TableMapping (type); _mappings [type.FullName] = map; //null here } return map; } This is what I do when my page loads public MainPage() { this