I am authorizing in a web application using ASP.NET SqlMembershipProvider, but when I call the GetUser method, it accidentally throws an invalid casting exception.
I can log in and navigate the pages all is well, but not at random points, a boom, it twitches and throws an exception:
Unable to cast object of type 'System.Int32' to type 'System.String'
By looking at the stack trace, you can clearly see that this is caused by the membership provider:
[InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.] System.Data.SqlClient.SqlBuffer.get_String() +5002910 System.Data.SqlClient.SqlDataReader.GetString(Int32 i) +55 System.Web.Security.SqlMembershipProvider.GetUser(String username, Boolean userIsOnline) +1169 System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline) +63 System.Web.Security.Membership.GetUser() +19 _Default.LoadLeadOverview() in \\file1\default.aspx.vb:169 _Default.Page_Load(Object sender, EventArgs e) in \\file1\default.aspx.vb:30 System.Web.UI.Control.OnLoad(EventArgs e) +91 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
I looked around and found other people with the same problem, but without a solution. Any thoughts would be welcome.
source share