nullreferenceexception

How to avoid a NullReferenceException

末鹿安然 提交于 2019-12-08 05:52:29
问题 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. 回答1: Is aClass a Type instance? If so - just check it for null: if (aClass != null && alMethSign[z]

Why am I getting a NullReferenceException from Membership.GetCurrentUserName?

六月ゝ 毕业季﹏ 提交于 2019-12-08 02:20:37
问题 I've just switched to using msbuild to precompile my website and now I'm getting this strange error: I have a call to Membership.GetUser() which throws: [NullReferenceException: Object reference not set to an instance of an object.] System.Web.Security.Membership.GetCurrentUserName() +36 System.Web.Security.Membership.GetUser() +7 ... 回答1: Reflector shows the implementation of Membership.GetCurrentUserName is: private static string GetCurrentUserName() { if (HostingEnvironment.IsHosted) {

Page.User.Identity.IsAuthenticated returns object reference not set to instance of object

元气小坏坏 提交于 2019-12-08 01:46:34
问题 this works fine on my local site but as soon as i upload the site to my live server i get stem.NullReferenceException: Object reference not set to an instance of an object on the first line of this: if (!Page.User.Identity.IsAuthenticated) { pnlSignIn.Visible = true; pnlSignOut.Visible = false; } 回答1: You should use Request.IsAuthenticated instead of Page.User.Identity.IsAuthenticated . Internally Request.IsAuthenticated will verify that the User and it's Identity are set (not null). You

NullReferenceException vs ArgumentNullException

瘦欲@ 提交于 2019-12-08 00:04:02
问题 I was reading this post where the answerer mentioned he prefered ArgumentNullException over NullReferenceException . MSDN mention that for NullReferenceException : The exception that is thrown when there is an attempt to dereference a null object reference. On ArgumentNullException they say: The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument. The answerer seems to say that you can use either. Is there

NullReferenceException when page Loads

℡╲_俬逩灬. 提交于 2019-12-07 23:49:18
问题 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

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

久未见 提交于 2019-12-07 20:58:51
问题 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... 回答1: 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

ASP.Net MVC RC2 ValidationMessage and form field conflict?

爷,独闯天下 提交于 2019-12-07 20:02:37
问题 I am having problems with MVC RC2 where upon validation failure, the failed field will throw a NullReferenceException when the view is passed back to the user. A short term solution was found: which was to rename the Html.ValidationMessage to be different than the Target Form Field. This works! BUT now the automatic highlighting is disconnected from the input field. (Out of the box behavour is to change the target field's CSS Class which makes it standout) So... What is the actual problem

ToString() returns null?

倖福魔咒の 提交于 2019-12-07 16:53:56
问题 I am trying to determine cause of 'Null reference exception' on published remote site. So, I can't debug it directly and can operate only with logs. So my question is: Is it possible, that .ToString() method of any of built-in .NET types returns null ? EDIT: I suspect DateTime.ToString(invariantCulture) method with badly constructed culture settings. 回答1: I don't know of any types where it does. It's not impossible - it would certainly be easy to write your own type which behaved like that -

How to inherit a UserControl from another UserControl?

拥有回忆 提交于 2019-12-07 06:49:32
问题 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 control, childusercontrol.ascx inheriting off of baseusercontrol.ascx. If I don't change anything in childusercontrol.ascx, I would expect the baseusercontrol.ascx text to display of "Stuff". And also I should be able to extend the base user control

NullReferenceException when creating a thread

泄露秘密 提交于 2019-12-07 05:04:33
问题 I was looking at this thread on creating a simple thread pool. There, I came across @MilanGardian's response for .NET 3.5 which was elegant and served my purpose: using System; using System.Collections.Generic; using System.Threading; namespace SimpleThreadPool { public sealed class Pool : IDisposable { public Pool(int size) { this._workers = new LinkedList<Thread>(); for (var i = 0; i < size; ++i) { var worker = new Thread(this.Worker) { Name = string.Concat("Worker ", i) }; worker.Start();