p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# 2008 aka C# 3.0 (http://p2p.wrox.com/forumdisplay.php?f=354)
-   -   Object reference not set to an instance of an object. (http://p2p.wrox.com/showthread.php?t=78872)

dotnet_user April 6th, 2010 02:36 PM

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

samjudson April 6th, 2010 04:46 PM

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.

msenthilkumarmca April 6th, 2011 06:11 AM

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.


All times are GMT -4. The time now is 11:25 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.