nullreferenceexception

ASP.Net MVC RC2 ValidationMessage and form field conflict?

*爱你&永不变心* 提交于 2019-12-06 09:22:31
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 with my code? AND Why wont it allow my ValidationMessage and Form fields share the same names? The code is

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

断了今生、忘了曾经 提交于 2019-12-06 06:53:36
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; } 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 could do the same in your code, but why bother. 来源: https://stackoverflow.com/questions/4519034/page-user

ToString() returns null?

僤鯓⒐⒋嵵緔 提交于 2019-12-05 19:01:29
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. 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 - but I doubt any of the framework types do. Do you have any particular types in mind? EDIT: DateTime.ToString

Always see NullReference exception in designer with all silverlight business applications in visual studio 2010

我与影子孤独终老i 提交于 2019-12-05 16:31:40
问题 Starting with the most simple case. If I press "File->new project->silverlight business application" it opens up to MainPage.xaml saying the message attached at the bottom of this post. It also does the same thing to any silverlight business application that exists in sourcesafe - this is the first time I've personally needed to work on this technology. Any advice would be very much appreciated I really need to get started on a project and I feel quite disabled to not have the designer.

NullReferenceException was unhandled by user code - Object reference not set to instance of an object [duplicate]

可紊 提交于 2019-12-05 10:30:38
This question already has answers here : What is a NullReferenceException, and how do I fix it? (31 answers) Closed 5 years ago . I have the following C# classes: public class Locales { public Region region { get; set; } public Buttons buttons { get; set; } public Fields fields { get; set; } } public class Region { public Center center { get; set; } public East east { get; set; } } public class Center { public string title { get; set; } } public class East { public string title { get; set; } } public class Buttons { public string save { get; set; } } public class Fields { public Labels labels

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

穿精又带淫゛_ 提交于 2019-12-05 08:40:38
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() at System.Web.UI.Page.SaveAllState() at System.Web.UI.Page.ProcessRequestMain(Boolean

NullReferenceException in creating Excel worksheet

假装没事ソ 提交于 2019-12-05 05:44:53
i want to fill an excel file and so i use ExcelPackage: Office Open XML Format . but i have an error. my code: string fileName = "DBE_BAKIM_FORMU" + ".xlsx"; FileInfo fi = new FileInfo(HttpContext.Current.Server.MapPath("~/") + fileName); using (ExcelPackage xlPackage = new ExcelPackage(fi)) { ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets[1]; dbeDataContext db = new dbeDataContext(); CAGRI c = (from x in db.CAGRIs where x.CagriID == ID select x).SingleOrDefault(); USER u = (from x in db.USERs where x.UserID == Convert.ToInt32(Session["user"]) select x).SingleOrDefault(); worksheet

Disposing the members that implement IDisposable

半城伤御伤魂 提交于 2019-12-05 02:38:53
In my Dispose methods (like the one below), everytime i want to call someObj.Dispose() i also have a check for someObj!=null. Is that because of bad design on my part? Is their a cleaner way to ascertain that Dispose of all the members (implementing IDisposable) being used in an object is called without having a risk of NullReference exception ? protected void Dispose(bool disposing) { if (disposing) { if (_splitTradePopupManager != null) { _splitTradePopupManager.Dispose(); } } } Thanks for your interest. Maybe someone else can chime in on this, but I don't personally think it's a design flaw

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

萝らか妹 提交于 2019-12-05 00:47:49
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? .NET code built with full optimizations and no debug info: your local variable names are gone, some local variables may have been eliminated entirely. .NET code built with full optimizations + PDB (or full debug): most local variable names

Cast null value to a type

末鹿安然 提交于 2019-12-04 23:22:28
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 operation? Cause if it really cast a null pointer it must be an error. Stephan According to the