Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
| Search | Today's Posts | Mark Forums Read
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 6th, 2010, 02:36 PM
Registered User
 
Join Date: Apr 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object reference not set to an instance of an object.

When I'm writing a unit test for failed authentication, I'm getting an error like this: Object reference not set to an instance of an object.

Here's my code(pretty simple):

//validate with wrong username
//The validation fails here(as expected) but I get the error: Object reference not set to an instance of an object.

ValidateUserResults validateUserTestFail = serviceClient.ValidateUser("wrongusername", "newPass1-i");
Assert.IsFalse(validateUserTestFail.Success, "Validate result should have been false");

// Authentication failed-wrong password
//The validation fails here too(as expected) but I don't get the error.

ValidateUserResults validateUserTestFail1 = serviceClient.ValidateUser("newuser1", "wrongpassword");
Assert.IsFalse(validateUserTestFail1.Success, "Validate result should have been true");

Can anybody please tell me why this is happening? I tried everything I can, but couldn't find a solution....

Thanks a lot in advance
  #2 (permalink)  
Old April 6th, 2010, 04:46 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

What is 'serviceClient'?

Obviously there is some code in the ValidateUser method that generates the error, so if you wrote that method go look in there.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
  #3 (permalink)  
Old April 6th, 2011, 06:11 AM
Registered User
 
Join Date: Sep 2004
Location: Madurai, Tamil Nadu, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What is the serviceClient? Whether you are creating an object or you are trying to access a Static Class? Anywhere you are trying to access any methods without initializing and instantiating a class inside your ValidateUser method? The exception may occur in the second method also but it don't reflect as the runtime stops the execution when it finds the exception.


Similar Threads
Thread Thread Starter Forum Replies Last Post
object reference not set to an instance of an object fraperz ASP.NET 3.5 Professionals 5 December 14th, 2009 03:45 AM
Object reference not set to an instance of an object. phuc2583 ASP.NET 3.5 Professionals 5 August 14th, 2009 10:56 AM
Chap 13 pg448: Object reference not set to an instance of an object tomche BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 15 August 8th, 2009 06:14 AM
Object Reference not set to an instance of object srinivas_chakka ASP.NET 1.0 and 1.1 Professional 0 February 8th, 2006 11:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.