Showing posts with label errors. Show all posts
Showing posts with label errors. Show all posts

Thursday, March 29, 2012

Object Reference error

I have a live ASP.NET site that in general runs very well. However, I am trapping errors and having the error message emailed to me. Everything will run fine but then sporadically, I will receive the following message:

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] MeetMarket3.SideBar.Page_Load(Object sender, EventArgs e) System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +35 System.Web.UI.Page.ProcessRequestMain() +750

Request URL: /sidebar.aspx

User:656
ScreenName:2lookingtoplay
Last SQL:exec dbo.spStateList

I am using Cookies to store the UserID and it appears as though this cookie information will get lost. Is there anything that could happen to cause Cookies to get reset?

Greg

There are a number of reasons ranging from why cookies get lost, including the user clearing them out or the plain old fact that they just expire. You must always code defensively when reading from cookies, query strings, form variables and so forth, which means that you must always check to see if the item is null/Nothing before you read from it.

Thanks.

I know that the user is not clearing them as this has happened to me while on the site.

I was under the empression that if you did not set an expiration that they would be valid at least throughout the current browser session. Is that not true?

Greg

Monday, March 26, 2012

Object reference not set to an instance of an object

Hello,

I have a .NET DLL which I am trying to call from an ASP .NET application. The DLL errors (Object reference not set to an instance of an object) when using a function from another DLL which is instantiated once successfully.

This DLL works perfectly when called from a VB.NET application.

ASP.NET:

Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

Dim objProgram As New WCS_DLL_Interface_Girobank_Split.WCS_DLL_Interface_Girobank_Split
objProgram.Run("040927", "C:\Inetpub\wwwroot\WCS_ASP_Interface_BulkPayments\App.config")
End If
End Sub

VB.NET DLL:

'Successfully creates instance
Dim objDB As New WCS_db_authentication.db

'Loop
'Error Line
strRAN = objDB.getData_ID(strAppPath, "WCS_SP_TMP_Girobank_Split_FindDebt", strWCS_SP_TMP_Girobank_Split_FindDebt)

'End Loop

I can't see why this would work in VB.NET and not ASP.NET. It creates the object fine (Even debugging "objDB is null" returns false).

Any one any ideas?

Cheers...what is the code for WCS_db_authentication.db

Woka
Originally posted by Wokawidget
what is the code for WCS_db_authentication.db

Woka

Seems it was a problem with a database function in wcs_db_authentication after all. Didn't have the correct permissions to connect.

Thanks for the reply.

Saturday, March 24, 2012

Object reference not set to an instance of an object - I hate these :)

Hi i hate these object reference not set to an instance of an object errors. Here's the code i have:

List<AnswersItem> answers = Answers.GetAnswers();
Hashtable newAnswers = new Hashtable();

foreach (Answer answer in answers)
{
if (newAnswers.ContainsKey(answer.QuestionID) && answer.Answer != newAnswers[answer.QuestionID].ToString())
{
// Log the answer
}

newAnswers[answer.QuestionID] = answer.Answer;
}

The problem

The line throwing the error is:

if (newAnswers.ContainsKey(answer.QuestionID) && answer.Answer != newAnswers[answer.QuestionID].ToString())

However i can't see what is wrong as i have set newAnswers to a new instance and i have checked if a key exists before using it but i still have an error. Appreciate if someone could help.

Thanks

answer.QuestionID or answer.Answer is null?


I think newAnswers Doesnt contains any think.

and also check for Answer veriable in loop.

Use debug , place breakpoint and used F10/F11 key , you definatly get solutions


Hi cheers it was answer.Answer returning null. I thought this property could not be null but some where it must have gone wrong. I have added a null check now.

Thanks for your help.

Friday, March 16, 2012

Object reference not set to an instance of an object.

G'day,

I'm feeling really ignorant but can't get past this error.
I don't seem to be able to fix without getting other syntax errors.

I'm copping this at the line marked with *

Sub getImg(ByVal FileID As Integer, ByVal ds As DataSet)
Dim dr As DataRow
Dim dt As DataTable

dt = ds.Tables("Images")

For Each dr In dt.Rows '*
If dr("fileID") = FileID Then

'set up some stuff

Exit For
End If
Next
End Sub

Incidently is there a slicker way of finding a record in a dataset?

Thanks,

GeoffI think you need to use the new keyword when u declare the datarow and the datatable.

Try


dim dr as new DataRow
dim dt as new DataTable


I could make dt a new instance but can't do the same for dr.
I get a message when mousing over 'dim dr as new DataRow' saying

'System.Data.DataRow.Protected Sub New(builder as System.Data.DataRowBuilder)' is not accessible in this context because it is 'Protected'.

Just when I was becoming confident I get something like this. I've no idea what's going on.

Thanks for your suggestion though!

Geoff
you do not need the new keyword for either statement as you arent creating new tables or rows. your just referencing other tables/rows.

my guess is that perhaps ds.Tables("Images") returned nothing.
Here is a link that will help you create DataTable and DataRows.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatatableclasstopic.asp

Object reference not set to an instance of an object. - Label

I am gettign the above error. My source errors out here:

Line 11: 'check if phone is listed to the public
Line 12: 'if not listed change label to warn user
Line 13: If CType(e.Item.FindControl("UnlistedLabel"), Label).Text = "True" Then
Line 14: CType(e.Item.FindControl("lblUnlisted"), Label).Visible = True
Line 15: End If

Full Sub Code:

Protected Sub DataList1_ItemDataBound(ByVal senderAs Object,ByVal eAs DataListItemEventArgs)
'check if phone is listed to the public
'if not listed change label to warn user
If CType(e.Item.FindControl("UnlistedLabel"), Label).Text ="True"Then
CType(e.Item.FindControl("lblUnlisted"), Label).Visible =True
End If
End Sub

Why is this happening, and weirded yet, it worked about 30 times until I restarted my computer. I have read and googled lots and seems like I should be able to called directly, but perhaps I need declare my labels first?

Any help would be appreciated.

I think you may have the variable names wrong, in one instance you search for "UnlistedLabel" and in the second you search for "lblUnlisted", I assume these are meant to reference the same object?

Thanks

Amar