nullreferenceexception

Linq to SQL NullReferenceException's: A random needle in a haystack!

I'm getting NullReferenceExeceptions at seemly random times in my application and can't track down what could be causing the error. I'll do my best to describe the scenario and setup. Any and all suggestions greatly appreciated! C# .net 3.5 Forms Application, but I use the WebFormRouting library built by Phil Haack (http://haacked....

Object reference not set to an instance of an object (NullreferenceException was unhandled by user code)

How can I get around this exception? Dim imagepathlit As Literal = DownloadsRepeater.FindControl("imagepathlit") imagepathlit.Text = imagepath Here is the repeater: <asp:Repeater ID="DownloadsRepeater" runat="server"> <HeaderTemplate> <table width="70%"> <tr> <td colspan="3"><h2>Files you can download</h2></td> </tr> </Heade...

Logging class using delegates (NullReferenceException)

I have created a small application but I would now like to incorporate some type of logging that can be viewed via listbox. The source of the data can be sent from any number of places. I have created a new logging class that will pass in a delegate. I think Im close to a solution but Im receiving a NullReferenceException and I don’t...

How to get interpolated message in NHibernate.Validator

Hi! 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 b...

C# says this.Controls is null, why?

Earlier my code was running nicely.. then I edited some .. did not touch the designer code. Why this error is being shown? ...

NullReferenceException in EntityFramework, how come?

Take a look at this query: var user = GetUser(userId); var sessionInvites = ctx.SessionInvites .Include("InvitingUser") .Include("InvitedUser") .Where(e => e.InvitedUser.UserId == user.UserId) .ToList(); var invites = sessionInvites; // Commenting out the two lines below, and it works as expected. foreach (var invite i...

Why would an error get thrown inside my try-catch?

Why would my try-catch block still be throwing an error when it's handled? Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Try Here >> : _MemoryStream.Seek(6 * StartOffset, 0) _MemoryStream.Read(_Buffer, 0, 6) Catch ex As...

Silverlight logging out causes "Object reference not set to an instance"

I am using the Silverlight 4 Business Application Template. I've created a DomainDataSource in XAML like so: <riaControls:DomainDataSource x:Name="LogData" QueryName="GetLogs" AutoLoad="True" LoadSize="20" > <riaControls:DomainDataSource.DomainContext> <local:AdminDomainContext /> </riaControls:DomainDataSour...

NullReferenceException when initializing NServiceBus within web application Application_Start method

I am running the 2.0 RTM of NServiceBus and am getting a NullReferenceException when my MessageModule binds the CurrentSessionContext to my NHibernate sessionfactory. From within my Application_Start, I call the following method: public static void WithWeb(IUnityContainer container) { log4net.Config.XmlConfigurator.Configure(); ...

Properly handling possible System.NullReferenceException in lambda expressions

Here's the query in question return _projectDetail.ExpenditureDetails .Where(detail => detail.ProgramFund == _programFund && detail.Expenditure.User == _creditCardHolder) .Sum(detail => detail.ExpenditureAmounts.FirstOrDefault( amount => amount.isCurrent && !amount.requiresAudit) .CommittedMonthlyRecord.Proj...

System.NullReferenceException with WhoCanHelpMe Unit Test

I'm working with a test project based on WhoCanHelpMe, which is based on Sharp Architecture, NHibernateValidator, etc. As its written the when_the_profile_tasks_is_asked_to_create_a_profile unit test creates the profile object and saves it without issue. Now the profile object is a CreateProfileDetails type that derives from their own V...

Query Parameter Value Is Null When Enum Item 0 is Cast with Int32

When I use the first item in a zero-based Enum cast to Int32 as a query parameter, the parameter value is null. I've worked around it by simply setting the first item to a value of 1, but I was wondering though what's really going on here? This one has me scratching my head. Why is the parameter value regarded as null, instead of 0? Enu...

File or Assembly Cannot be Loaded Error

I am working on a Setup program which creates a .msi file. There is a CustomAction program associated with it which is written in C#. There are three COM object references made in this CustomAction program which are necessary in order for it to work. They are as follows. Active DS IIS Namespace Provide (C:\Windows\System32\inetsr...

null reference exception in the code

I am getting NullReferenceException error on "_attr.Append(xmlNode.Attributes["name"]);". namespace SMAS { class Profiles { private XmlTextReader _profReader; private XmlDocument _profDoc; private const string Url = "http://localhost/teamprofiles.xml"; private const string XPath = "/teams/team-profile"; public Xml...

Null reference for first memory address between 0 - 65535

I would like to understand a bit more about memory and I was unable to find it from Google, please forgive me if this is silly question. How come the following code, accessing memory address 0(and up to 65535) in C# would throw NullReferenceException byte* pointer = (byte*)0; byte test = *pointer; Thanks a lot in advance! ...

ASP.NET C# DataList FindControl & Header/Footer template causes error

Hello, whenever I use the Header or Footer template of DataList, FindControl is unable to find a label part of the DataList, and throws a NullReferenceException. My SQLDataSource and DataList (no Header and Footer template - works): <asp:SqlDataSource ID="sdsMinaKop" runat="server" ConnectionString="<%$ ConnectionStri...

Problem with Unit testing of ASP.NET project (NullReferenceException when running the test)

Hi, I'm trying to create a bunch of MS visual studio unit tests for my n-tiered web app but for some reason I can't run those tests and I get the following error - "Object reference not set to an instance of an object" What I'm trying to do is testing of my data access layer where I use LINQ data context class to execute a cert...

How to check for a null object reference when validating forms in MVC

Hello SO, I'm experimenting with validating forms in the asp.net MVC framework. I'm focusing on server side validation for the time being. I've come across an error that I'm not sure how to rectify. System.NullReferenceException: Object reference not set to an instance of an object. The code that throws the error is: [AcceptVerb...

Having trouble debugging class library plugin

Hi all. I have a windows form application in which I'm attempting to utilize a plugin (class library). In the code I have it load the assembly from a dll file, which means I have not been able to debug. Furthermore I have not found out how to compile the library so I've had to use the debuged dll version for testing. I've run into a bug ...

How to invoke a delegate with a null parameter?

I get a null exception if I try to pass a null parameter to a delegate during an invoke. Here's what the code looks like: public void RequestPhoto() { WCF.Service.BeginGetUserPhoto(Contact.UserID, new AsyncCallback(RequestPhotoCB), null); } public void RequestPhotoCB(IAsyncR...