1

I have used,

CommunitySystem.CurrentContext.DefaultSecurity.RemoveUser(IUser user);

To remove user (Just as the answer posted in this issue).

However, this works fine. But for one user it gives an error. The exception throws from the RemoveUser(IUser user).

The exception details are here as below,

System.ArgumentNullException: The type cannot be null. Parameter name: type 
at EPiServer.Data.Entity.Internal.EntityTypeResolver.GetTypeName(Type type, Boolean ignoreOverrideAttribute) 
at EPiServer.Common.ImplementationModule.HandleCommentAddUpdateRemove(IComment comment, SupportedOperations operation) 
at EPiServer.Common.Comments.CommentHandler.OnCommentUpdated(IComment comment) 
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass32_0.b__0() 
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass33_0`1.b__0() 
at EPiServer.Common.Comments.CommentHandler.UpdateComment(IComment comment) 
at EPiServer.Common.Data.FrameworkFactoryBase.CascadeUpdateStatus(IEntityStatus entity, ICollection`1 children) 
at EPiServer.Common.Data.CommentFactory.CascadeAuthorStatus(IAuthor author) 
at EPiServer.Common.AuthorEventHandler.Invoke(EntityEventArgs args) 
at EPiServer.Common.AuthorHandler.OnAuthorUpdated(IAuthor author) 
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass32_0.b__0() 
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass33_0`1.b__0() 
at EPiServer.Common.AuthorHandler.UpdateAuthor(IAuthor author) 
at EPiServer.Common.Data.FrameworkFactoryBase.CascadeUpdateStatus(IEntityStatus entity, ICollection`1 children) 
at EPiServer.Common.Security.Data.SecurityFactory.<>c__DisplayClass57_0.b__0() 
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass32_0.b__0() 
at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass33_0`1.b__0() 
at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method) 
at EPiServer.Common.Security.SecurityHandler.RemoveUser(IUser user)

I have tried to extract the Type and Type Name and it worked fine.

IUser user = getUser(id);
Type type = user.AccessRightsType;
string typeName = new EPiServer.Data.Entity.Internal.EntityTypeResolver().GetTypeName(type, true); // Not null. This value is as same as on other users

Update: I have decompiled the EPiServer.Common.ImplementationModule and this is what the HandleCommentAddUpdateRemove(..) has.

private static void HandleCommentAddUpdateRemove(IComment comment, SupportedOperations operation) {
    EntityReference commentedEntity = comment.CommentedEntity;
    IComment comment2 = null;
    CommentEventData commentEventData;
    if ((int) operation == 4) {
        comment2 = (IComment) comment.get_Master();
        if (comment2 == null || comment2.Status == comment.Status) {
            return;
        }
        commentedEntity = comment2.CommentedEntity;
        commentEventData = new CommentEventData(IEntityTypeResolverExtensions.GetTypeName(ServiceLocator.get_Current().GetInstance < IEntityTypeResolver > (), commentedEntity.get_Type()), commentedEntity.get_ID(), comment2.Status, -1);
        m_commentEvent.Raise(m_commentId, (object) commentEventData);
    }
    commentEventData = new CommentEventData(IEntityTypeResolverExtensions.GetTypeName(ServiceLocator.get_Current().GetInstance < IEntityTypeResolver > (), commentedEntity.get_Type()), commentedEntity.get_ID(), comment.Status, ((int) operation != 8) ? 1 : (-1));
    m_commentEvent.Raise(m_commentId, (object) commentEventData);
}

What causes this to happen ?

It seems like the below code returns 'Null'

commentedEntity.get_Type();

Any way to delete this user?

Additional info:

EPiServer.CommonFramework version=9.0.1
EPiServer.CMS.Core version=11.11.0
EPiServer.Community version=9.0.0
Senura Dissanayake
  • 654
  • 1
  • 9
  • 29
  • 1
    Looks like it has something to do with it trying to remove the user's comments (`HandleCommentAddUpdateRemove`) which in turn invokes `GetTypeName`, but I haven't worked with Community at all. Regardless, you might be better off posting questions on Community on world.episerver.com. – Ted Nyberg Dec 06 '18 at 07:58
  • @TedNyberg Thanks. Posted the issue in [Episerver developer forums](https://world.episerver.com/forum/developer-forum/Problems-and-bugs/Thread-Container/2019/5/error-occurred-when-removing-the-user-in-episerver---argumentnullexception-the-type-cannot-be-null/) – Senura Dissanayake May 15 '19 at 10:54

0 Answers0