diff --git a/src/Microsoft.AspNet.Identity.EntityFramework/RoleStore.cs b/src/Microsoft.AspNet.Identity.EntityFramework/RoleStore.cs index 8adbde0568..c8d3a61efa 100644 --- a/src/Microsoft.AspNet.Identity.EntityFramework/RoleStore.cs +++ b/src/Microsoft.AspNet.Identity.EntityFramework/RoleStore.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Security.Claims; using System.Threading; @@ -160,7 +161,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework { return default(TKey); } - return (TKey)Convert.ChangeType(id, typeof(TKey)); + return (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(id); } public virtual string ConvertIdToString(TKey id) diff --git a/src/Microsoft.AspNet.Identity.EntityFramework/UserStore.cs b/src/Microsoft.AspNet.Identity.EntityFramework/UserStore.cs index bf5c2d0828..6e8e75c375 100644 --- a/src/Microsoft.AspNet.Identity.EntityFramework/UserStore.cs +++ b/src/Microsoft.AspNet.Identity.EntityFramework/UserStore.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Globalization; using System.Linq; using System.Security.Claims; @@ -212,7 +213,7 @@ namespace Microsoft.AspNet.Identity.EntityFramework { return default(TKey); } - return (TKey)Convert.ChangeType(id, typeof(TKey)); + return (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(id); } public virtual string ConvertIdToString(TKey id) diff --git a/src/Microsoft.AspNet.Identity.EntityFramework/project.json b/src/Microsoft.AspNet.Identity.EntityFramework/project.json index 3e7bb7d723..76e2fa0ede 100644 --- a/src/Microsoft.AspNet.Identity.EntityFramework/project.json +++ b/src/Microsoft.AspNet.Identity.EntityFramework/project.json @@ -12,6 +12,7 @@ "dependencies": { "System.Collections": "4.0.10-beta-*", "System.ComponentModel": "4.0.0-beta-*", + "System.ComponentModel.TypeConverter": "4.0.0-beta-*", "System.Diagnostics.Debug": "4.0.10-beta-*", "System.Diagnostics.Tools": "4.0.0-beta-*", "System.Globalization": "4.0.10-beta-*", diff --git a/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreGuidKeyTest.cs b/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreGuidKeyTest.cs index bd96137d97..ae79a5d2bc 100644 --- a/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreGuidKeyTest.cs +++ b/test/Microsoft.AspNet.Identity.EntityFramework.Test/UserStoreGuidKeyTest.cs @@ -43,21 +43,11 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test public class ApplicationUserStore : UserStore { public ApplicationUserStore(TestDbContext context) : base(context) { } - - public override Guid ConvertIdFromString(string userId) - { - return new Guid(userId); - } } public class ApplicationRoleStore : RoleStore { public ApplicationRoleStore(TestDbContext context) : base(context) { } - - public override Guid ConvertIdFromString(string id) - { - return new Guid(id); - } } protected override void AddUserStore(IServiceCollection services, object context = null)