Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using guid response a cast error #77

Open
eld1887 opened this issue Jul 9, 2018 · 3 comments
Open

using guid response a cast error #77

eld1887 opened this issue Jul 9, 2018 · 3 comments
Labels

Comments

@eld1887
Copy link

eld1887 commented Jul 9, 2018

hi,
i get the error:

Invalid cast from 'System.UInt64' to 'System.Guid'. System.InvalidCastException: Invalid cast from 'System.UInt64' to 'System.Guid'. at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) at Dapper.SqlMapper.Parse[T](Object value) in C:\projects\dapper\Dapper\SqlMapper.cs:line 2969 at Dapper.SqlMapper.<ExecuteScalarImplAsync>d__641.MoveNext() in C:\projects\dapper\Dapper\SqlMapper.Async.cs:line 1193`

this is my ConfigureServices:

public void ConfigureServices(IServiceCollection services)
        {
            

            services.ConfigureDapperConnectionProvider<MySqlConnectionProvider>(Configuration.GetSection("DapperIdentity"))
                    .ConfigureDapperIdentityCryptography(Configuration.GetSection("DapperIdentityCryptography"))
                    .ConfigureDapperIdentityOptions(new DapperIdentityOptions { UseTransactionalBehavior = false }); //Change to True to use Transactions in all operations
            

            services.AddIdentity<CustomUser, CustomRole>(x =>
                                                         {
                                                             x.Password.RequireDigit = false;
                                                             x.Password.RequiredLength = 1;
                                                             x.Password.RequireLowercase = false;
                                                             x.Password.RequireNonAlphanumeric = false;
                                                             x.Password.RequireUppercase = false;
                                                         })


                .AddDapperIdentityFor<MySqlConfiguration, Guid>()
                    .AddDefaultTokenProviders();

            services.AddMvc();

CustomUser and CustomRole:

public class CustomUser : DapperIdentityUser<Guid>
    {
        public string FirstName { get; set; }

        public CustomUser() { }
        public CustomUser(string userName) : base(userName) { }
    }

    public class CustomRole : DapperIdentityRole<Guid>
    {

        public CustomRole() { }
        public CustomRole(string roleName) : base(roleName)
        {
        }
    }

I changed the table for identityUser (MySql) like so:

CREATE TABLE IF NOT EXISTS `identityuser` (
  `Id` CHAR(36) NOT NULL,
  `Username` varchar(256) NOT NULL,
  `Email` varchar(256) DEFAULT NULL,
  `FirstName` varchar(256) DEFAULT NULL,
  `EmailConfirmed` bit(1) NOT NULL,
  `PasswordHash` longtext,
  `SecurityStamp` varchar(38) DEFAULT NULL,
  `PhoneNumber` varchar(50) DEFAULT NULL,
  `PhoneNumberConfirmed` bit(1) NOT NULL,
  `TwoFactorEnabled` bit(1) NOT NULL,
  `LockoutEnd` datetime DEFAULT NULL,
  `LockoutEnabled` bit(1) NOT NULL,
  `AccessFailedCount` int(11) NOT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

Is that a mistake from my side or is that a general bug?

EDIT
if i register someone the data is insert in the database, but i get the error message from above

@grandchamp
Copy link
Owner

That is a bit weird, since Dapper itself is trying to convert UInt64 to GUID. I'll investigate.

@grandchamp grandchamp added the bug label Jul 10, 2018
@rippo
Copy link

rippo commented Jul 11, 2018

I believe this is a mysql connector issue and not an issue in Dapper.
I tend to use id BINARY(16) NOT NULL,

@grandchamp
Copy link
Owner

grandchamp commented Jul 11, 2018

Did you guys try to update MySQL Connector version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants