public async Task <IdentityUser> FindByIdAsync(string userId, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException(nameof(userId)); } try { var key = default(string); var converter = TypeDescriptor.GetConverter(typeof(string)); if (converter != null && converter.CanConvertFrom(typeof(string))) { key = (string)converter.ConvertFromInvariantString(userId); } else { key = (string)Convert.ChangeType(userId, typeof(string)); } var result = await _userRepository.GetByIdAsync(key); return(result); } catch (Exception ex) { Logging.LogException(ex); return(null); } }