Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nurhak Kaya 53 posts 147 karma points MVP 3x c-trib
    Apr 24, 2018 @ 14:56
    Nurhak Kaya
    0

    Intermittent CreateAsync SqlException while Creating an Umbraco Member

    Intermittently I see that CreateAsync method throws the following SqlException while creating Umbraco members. Has anybody seen this before and hopefully fixed it please? This looks like an Umbraco bug which hasn't been reported, yet.

    enter image description here

    Details:

    Umbraco version 7.5.7 assembly: 1.0.6219.11990

    Method that throws the exception intermittently:

        private static async Task<UmbracoApplicationMember> CreateMember(UmbracoMembersUserManager<UmbracoApplicationMember> uMgr, string loginName, string properName, UserLoginInfo loginInfo)
        {
            var user = new UmbracoApplicationMember
            {
                Name = properName,
                UserName = loginName,
                Email = loginName
            };
    
            var result = await uMgr.CreateAsync(user); // This is where the exception is thrown intermittently
         // The rest of the code...
    

    Further Details:

    CreateAsync:

    Assembly Microsoft.AspNet.Identity.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
            //
            // Summary:
            //     Create a user with no password
            //
            // Parameters:
            //   user:
            [AsyncStateMachine(typeof(UserManager<,>.<CreateAsync>d__0))]
            [DebuggerStepThrough]
            public virtual Task<IdentityResult> CreateAsync(TUser user);
    

    UmbracoIdentity:

      #region Assembly UmbracoIdentity, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
    // D:\tfs\MYPROJECT\DEV\WEB\MYPROJECT.Web\packages\UmbracoIdentity.Core.5.0.0\lib\net45\UmbracoIdentity.dll
    #endregion
    
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.Owin;
    using Umbraco.Core.Logging;
    using Umbraco.Core.Persistence;
    using Umbraco.Core.Persistence.SqlSyntax;
    using Umbraco.Core.Services;
    using UmbracoIdentity.Models;
    
    namespace UmbracoIdentity
    {
        public class UmbracoMembersUserManager<TUser> : UserManager<TUser, int> where TUser : UmbracoIdentityMember, IUser<int>, new()
        {
            public UmbracoMembersUserManager(IUserStore<TUser, int> store);
    
            public override bool SupportsQueryableUsers { get; }
            public override bool SupportsUserLockout { get; }
            public override bool SupportsUserSecurityStamp { get; }
            public override bool SupportsUserTwoFactor { get; }
            public override bool SupportsUserPhoneNumber { get; }
    
            public static UmbracoMembersUserManager<TUser> Create(IdentityFactoryOptions<UmbracoMembersUserManager<TUser>> options, ILogger logger, ISqlSyntaxProvider sqlSyntax, UmbracoDatabase database, IMemberService memberService, IMemberTypeService memberTypeService, IMemberGroupService memberGroupService, IdentityEnabledMembersMembershipProvider membershipProvider = null);
            public static UmbracoMembersUserManager<TUser> Create(IdentityFactoryOptions<UmbracoMembersUserManager<TUser>> options, IMemberService memberService, IMemberTypeService memberTypeService, IMemberGroupService memberGroupService, IExternalLoginStore externalLoginStore = null, IdentityEnabledMembersMembershipProvider membershipProvider = null);
            public static UmbracoMembersUserManager<TUser> Create(IdentityFactoryOptions<UmbracoMembersUserManager<TUser>> options, UmbracoMembersUserStore<TUser> customUserStore, IdentityEnabledMembersMembershipProvider membershipProvider = null);
            protected override void Dispose(bool disposing);
        }
    }
    

    UmbracoApplicationMember:

        using System.Security.Claims;
    using System.Threading.Tasks;
    using Microsoft.AspNet.Identity;
    using UmbracoIdentity;
    using UmbracoIdentity.Models;
    
    namespace MYPROJECT.Web.Presentation.Models.UmbracoIdentity
    {
        public class UmbracoApplicationMember : UmbracoIdentityMember
        {
            public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<UmbracoApplicationMember, int> manager)
            {
                // Note the authenticationType must match the one 
                // defined in CookieAuthenticationOptions.AuthenticationType
                var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
    
                // Add custom user claims here
                return userIdentity;
            }
        }
    }
    
  • muhammad 5 posts 74 karma points
    Oct 05, 2020 @ 14:19
    muhammad
    0

    With reference to this

    The below should work

    And supported in async as well.

    var repositoryFactory = new RepositoryFactory();
    IScopeUnitOfWorkProvider uowProvider = new etaPocoUnitOfWorkProvider();                
    using (var uow = uowProvider.GetUnitOfWork(readOnly: true))
    {
        using (var repository = repositoryFactory.CreateContentRepository(uow))
        {
            var x = repository.GetAll(guids);
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft