1
votes

We have a live running business system with an error which occurs from time to time. The error is according to the stack trace comming from the asp.net membership provider. It does not seem to matter which user is currently logged on. As far as i can tell the asp.net membership tables in the database are fine.

Example of a code row generating the error:

if (Membership.GetUser() != null)

Error description:

Unable to cast object of type 'System.Int32' to type 'System.String'.

Stack Trace:

[InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.]
System.Data.SqlClient.SqlBuffer.get_String() +141
System.Data.SqlClient.SqlDataReader.GetString(Int32 i) +96
System.Web.Security.SqlMembershipProvider.GetNullableString(SqlDataReader reader, Int32 col) +35
System.Web.Security.SqlMembershipProvider.GetUser(String username, Boolean userIsOnline) +1110
System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline) +82
System.Web.Security.Membership.GetUser() +19

Does anyone have an idea of what's wrong?


Update: We could not find a solution for this error. But eventually it disapeared.

Now when we migrated to another server this error totally cripples our application. I'm totally out of ideas :(

1
It appears to be happening low on the stack...Chuck Conway
Yikes - we have the same problem right now - no idea.Perhentian
Man, I'm getting this too and it drives me nuts. I feel like I need to write my own membership provider.Mr Rogers

1 Answers

0
votes

Put a try/catch block around the Membership.GetUser() call and log the username. You can get the username by calling Membership.GetCurrentUserName().

Once you have a username this is causing problems for, look at the membership table in SQL and check out the Comments field. My guess is that something funny is going on in the Comments field - maybe there are some weird unicode characters it's having trouble with, or maybe there's too much data in that field, etc.

Also, try calling dbo.aspnet_Membership_GetUserByName on the membership database for the user that it had trouble with and see what result you get.