locked
Creating User via SDK Fails with Crm Exception: Message: usersettings With Id = <guid> Does Not Exist, ErrorCode: -2147220969 RRS feed

  • Question

  • Hi,

    I have CRM 2013 SP1 UR3 on premise. I am trying to create a user via the SDK, but the create fails saying usersettings do not exist for this user, which of course they don't since I am creating the user! In the CRM trace it seems CRM is doing some mailbox processing. I can create users OK via the UI, but not via the SDK. The SDK call is very simple:

                WhoAmIRequest whoRequest = new WhoAmIRequest();
                WhoAmIResponse whoResponse = (WhoAmIResponse)xrmService.Execute(whoRequest);
                Guid businessUnitId = whoResponse.BusinessUnitId;
                Entity systemUser = new Entity("systemuser");
                systemUser["domainname"] = @"dev\firstname.lastname";
                systemUser["businessunitid"] = new EntityReference("businessunit",businessUnitId);
                Guid systemUserId = xrmService.Create(systemUser);

    It seems there is a bug in CRM? I tried this on a uncustomised CRM instance with no plugins.

    This the CRM trace:

    Process: w3wp |Organization:30a2c455-f4c8-442d-a2ee-e3dac4864bda |Thread:   11 |Category: Exception |User: e652c3ff-7a0f-e511-80bb-000d3ab07d34 |Level: Error |ReqId: e59059dc-84ef-4ddf-a33e-c2e2d3be7ad0 | CrmException..ctor  ilOffset = 0x7
     at CrmException..ctor(String message, Exception innerException, Int32 errorCode, Boolean isFlowControlException)  ilOffset = 0x7
     at CrmException..ctor(String message, Int32 errorCode)  ilOffset = 0x5
     at CrmObjectNotFoundException..ctor(BusinessEntityMoniker moniker)  ilOffset = 0x39
     at BusinessProcessObject.Retrieve(BusinessEntityMoniker moniker, EntityExpression entityExpression, ExecutionContext context, Int32 languageCode, DatabaseQueryTarget queryTarget)  ilOffset = 0x19
     at BusinessProcessObject.Retrieve(BusinessEntityMoniker moniker, EntityExpression entityExpression, ExecutionContext context, Int32 languageCode)  ilOffset = 0x7
     at BusinessProcessObject.Retrieve(BusinessEntityMoniker moniker, EntityExpression entityExpression, ExecutionContext context)  ilOffset = 0xF
     at UserDataCacheLoader.RetrieveUserSettings(Guid& key, ProvisionSystemUserService userService, ExecutionContext context)  ilOffset = 0x2F
     at UserDataCacheLoader.LoadCacheData(Guid key, ExecutionContext context)  ilOffset = 0xD6
     at ObjectModelCacheLoader`2.LoadCacheData(TKey key, IOrganizationContext context)  ilOffset = 0x31
     at CrmMultiOrgCacheBase`2.CreateEntry(TKey key, IOrganizationContext context)  ilOffset = 0x8
     at CrmMultiOrgCacheBase`2.LookupEntry(TKey key, IOrganizationContext context)  ilOffset = 0x26
     at MailboxServiceInternal`1.CreateDefaultMailbox(ReferencingEntityMailboxSynchronizerContext`1 referencingEntityContext, IBusinessEntity entity, Guid ownerId, Int32 ownerType, BusinessEntityMoniker moniker, ExecutionContext context)  ilOffset = 0x37
     at <>c__DisplayClass6.<CreateDefaultMailbox>b__4()  ilOffset = 0x45
     at MailboxSynchronizer`1.ExecuteInProperContext(Action body, Boolean isProvisioning, ExecutionContext context)  ilOffset = 0x11
     at SystemUserServiceInternal`1.CreateDefaultMailbox(Object sender, ExtensionEventArgs args)  ilOffset = 0x79
     at PostCreateEventHandler.Invoke(Object sender, ExtensionEventArgs e)  ilOffset = 0xFFFFFFFF
     at BusinessProcessObject.Create(IBusinessEntity entity, ExecutionContext context)  ilOffset = 0x6C
     at SystemUserServiceInternal`1.CreateInternal(Guid organizationId, IBusinessEntity systemuser, ExecutionContext context)  ilOffset = 0x3AC
     at SystemUserServiceInternal`1.Create(IBusinessEntity systemuser, ExecutionContext context)  ilOffset = 0x225
     at RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)  ilOffset = 0xFFFFFFFF
     at RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)  ilOffset = 0x25
     at RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)  ilOffset = 0xCF
     at LogicalMethodInfo.Invoke(Object target, Object[] values)  ilOffset = 0x4F
     at InternalOperationPlugin.Execute(IServiceProvider serviceProvider)  ilOffset = 0x57
     at V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)  ilOffset = 0x200
     at VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)  ilOffset = 0x65
     at Pipeline.Execute(PipelineExecutionContext context)  ilOffset = 0x65
     at MessageProcessor.Execute(PipelineExecutionContext context)  ilOffset = 0x1C5
     at InternalMessageDispatcher.Execute(PipelineExecutionContext context)  ilOffset = 0xE4
     at ExternalMessageDispatcher.ExecuteInternal(IInProcessOrganizationServiceFactory serviceFactory, IPlatformMessageDispatcherFactory dispatcherFactory, String messageName, String requestName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, ParameterCollection fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId, Guid transactionContextId, Int32 invocationSource, Nullable`1 requestId, Version endpointVersion)  ilOffset = 0x16E
     at OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, UserAuth userAuth, Guid targetUserId, OrganizationContext context, Boolean returnResponse, Boolean checkAdminMode)  ilOffset = 0x1F1
     at OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode)  ilOffset = 0x2D
     at OrganizationSdkServiceInternal.Create(Entity entity, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode)  ilOffset = 0x39
     at OrganizationSdkService.Create(Entity entity)  ilOffset = 0x12
     at   ilOffset = 0xFFFFFFFF
     at SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)  ilOffset = 0x241
     at DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)  ilOffset = 0x100
     at ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)  ilOffset = 0x48
     at MessageRpc.Process(Boolean isOperationContextSet)  ilOffset = 0x62
     at Wrapper.Resume(Boolean& alreadyResumedNoLock)  ilOffset = 0x1B
     at ThreadBehavior.SynchronizationContextStartCallback(Object state)  ilOffset = 0x0
     at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  ilOffset = 0x70
     at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  ilOffset = 0x4
     at QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()  ilOffset = 0x0
     at ThreadPoolWorkQueue.Dispatch()  ilOffset = 0xA2
    >Crm Exception: Message: usersettings With Id = 559b5588-e461-e511-80dd-000d3ab0d186 Does Not Exist, ErrorCode: -2147220969

    Wednesday, September 23, 2015 11:30 AM

Answers

  • The answer my friends is to set the user's first name and last name. Unlike the UI which obtains the user's name from Active Directory, when using the SDK you need to set the user's name. A shame CRM doesn't give you a proper error message. So adding these 2 lines solved the problem:

    systemUser["firstname"] = "first-name";

    systemUser["lastname"] = "last-name";

    • Marked as answer by Caratacus Thursday, September 24, 2015 8:29 AM
    Thursday, September 24, 2015 8:29 AM