Click here to Skip to main content
15,908,841 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
please help me in finding the solution of the problem

MembershipUserCollection users = new MembershipUserCollection();


users = Membership.GetAllUsers();
it shows the exception like this...

Exception Details: System.InvalidCastException: Specified cast is not valid.


it was working fine few hours ago and i was able to get all users from the database.....
i dont know what happened....
plz help me in this...very critical...
Posted

1 solution

Once worked and now not working generally means, it is not referring the correct type.

The reference to System.Web.Security may be removed or the project may be corrupted. Check you have the reference still.

It can also happen if you define a class in your project with same name like "Membership" or "MembershipUserCollection".

You can try using the fully qualified name and check like...

System.Web.Security.MembershipUserCollection users = new System.Web.Security.MembershipUserCollection();

users = System.Web.Security.Membership.GetAllUsers();
 
Share this answer
 
Comments
mutex_semaphore 5-Mar-11 11:59am    
Thanks, i solved my problem. But it was not something you presented.
It was because there were some problems in the ASPNET_USERS table in database.
I actually created a table in database and i made one of the column of the table as foreign key with the ASPNET_USERS table, that made the error.....
It is very strange kind of error.....
I am still thankful for paying ur attention about my problem....

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