Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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:


Line 22: ENTUserAccount userAccount = db.ENTUserAccounts.SingleOrDefault(ua => ua.WindowsAccountName == @"VARALLO1\VaralloMadison");
Line 23:
Line 24: ViewState["ENTUserAccountId"] = userAccount.ENTUserAccountId;
Line 25: ViewState["InsertENTUserAccountId"] = userAccount.InsertENTUserAccountId;
Line 26: ViewState["InsertDate"] = userAccount.InsertDate;
Posted
Comments
Er Daljeet Singh 26-Sep-13 6:25am    
Will you please post the code where you are getting error.
[no name] 26-Sep-13 6:30am    
So debug your code, find out which object that you are trying to use that is null, make it not null.

1 solution

The most obvious reason is that SingleOrDefault returns null if it doesn't find any matching records - so you need to check that userAccount is not null before you use it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900