Bug #56002 Connector/.Net GetUserId throws InvalidCast Exception
Submitted: 16 Aug 2010 9:00 Modified: 14 Dec 2010 22:15
Reporter: Diogo Cunha Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version: OS:Windows (7)
Assigned to: Reggie Burnett CPU Architecture:Any

[16 Aug 2010 9:00] Diogo Cunha
Description:
I'm trying to do a simple thing: using.Net MVC with MySQL 5.1.39.
The problem happens on the GetUserId function on the connector that throws an invalidcast exception when i try to login with a created user! I just used the default code given by the MVC Application template in VS2008, so it should be quite straight forward, right?

This happened with the 6.2.3 and 6.1.4 versions of the connector

[InvalidCastException: Specified cast is not valid.]
   MySql.Web.Security.MySQLMembershipProvider.GetUserId(MySqlConnection connection, String username) +177
   MySql.Web.Security.MySQLMembershipProvider.ValidateUser(String username, String password) +89
   JogoABola.Controllers.AccountMembershipService.ValidateUser(String userName, String password) in C:\Users\Diogo\Desenvolvimento\jogoabola\JAB\JogoABola\Controllers\AccountController.cs:335
   JogoABola.Controllers.AccountController.ValidateLogOn(String userName, String password) in C:\Users\Diogo\Desenvolvimento\jogoabola\JAB\JogoABola\Controllers\AccountController.cs:207
   JogoABola.Controllers.AccountController.LogOn(String userName, String password, Boolean rememberMe, String returnUrl) in C:\Users\Diogo\Desenvolvimento\jogoabola\JAB\JogoABola\Controllers\AccountController.cs:59
   lambda_method(ExecutionScope , ControllerBase , Object[] ) +245
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
[...]

The Web.Config part looks like this:
[...]
<membership defaultProvider="MySQLMembershipProvider2">
   <providers>
    <add autogenerateschema="true" connectionStringName="JABMySqlServer"
     enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false"
     applicationName="/" requiresUniqueEmail="true" passwordFormat="Clear"
     minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0"
     maxInvalidPasswordAttempts="5" passwordAttemptWindow="5" passwordAnswerAttemptLockoutDuration="30"
     passwordStrengthRegularExpression="" name="MySQLMembershipProvider2"
     type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
   </providers>
  </membership>
		<profile defaultProvider="MySQLProfileProvider2">
			<providers>

				<add name="MySqlProfileProvider2" autogenerateschema="true" connectionStringName="JABMySqlServer" applicationName="/" type="MySql.Web.Security.MySQLProfileProvider, MySql.Web, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
			</providers>
		</profile>
		<roleManager enabled="true" defaultProvider="MySqlRoleProvider2">
   <providers>
    <add autogenerateschema="true" connectionStringName="JABMySqlServer"
     applicationName="/" name="MySqlRoleProvider2" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
   </providers>
  </roleManager>
[...]

How to repeat:
Install the Connector/Net 6.2.3 and use a MVC template in VS2008. 
Then create a user and try to login.
[14 Dec 2010 22:15] Reggie Burnett
I tried to reproduce this using 5.1.45 and the latest source repos of Connector/Net 6.0, 6.1, and 6.2.  I could not recreate this behavior.  Can you try using later versions as 6.1.5 and 6.2.4 are available for use.

If you still see this problem, please reopen and give us that info.