locked
OData - Server error when creating a Dynamics user RRS feed

  • Question

  •  Hi,          

    I'm trying to create a Dynamics CRM user programmatically via the OData client.

    The following code fails with a 500 InternalServerError, while the exact same operation (same creator, same user data) succeeds if I go the manual way via the CRM web interface.

    var client = new ODataClient(

    new ODataClientSettings(url, CredentialCache.DefaultCredentials)
                {
                    RequestTimeout = TimeSpan.FromMinutes(2),
                    MetadataDocument = metadata,
                    Credentials = new System.Net.NetworkCredential("mylogin", "mypwd", "mydomain")
                };

    );
    var newUser = new DTOs.SystemUser {                firstname = "John",                lastname = "Doe",                domainname = @"mydomain\jdoe" // also tried with the @mydomain syntax and double backslash here };            var generatedUser = await client .For<DTOs.SystemUser>("SystemUsers") .Set(newUser)                .InsertEntryAsync();


    Also note that a few lines before this, I read from Dynamics (FindEntryAsync()) with the same ODataClientSettings as above and it works perfectly.

    I enabled Dynamics logging and the only relevant line I get in the logs is the following :

    MessageProcessor fail to process message 'Create' for 'systemuser'.

     
    at MessageProcessor.Execute(PipelineExecutionContext context)  ilOffset = 0x1E6$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 callerRegardingObjectId, UserType userType, Guid transactionContextId, Int32 invocationSource, Nullable`1 requestId, Version endpointVersion)  ilOffset = 0x1F2$at ExternalMessageDispatcher.Execute(IInProcessOrganizationServiceFactory serviceFactory, IPlatformMessageDispatcherFactory dispatcherFactory, String messageName, String requestName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, ParameterCollection fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId, Guid callerRegardingObjectId, UserType userType, Guid transactionContextId, Int32 invocationSource, Nullable`1 requestId)  ilOffset = 0x0$at OrganizationSdkServiceInternal.ExecuteRequestRequestWithInstrumentation(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, UserAuth userAuth, Guid targetUserId, OrganizationContext context, Boolean returnResponse, Boolean checkAdminMode, Object operation, UserType targetUserType)  ilOffset = 0x0$at OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext)  ilOffset = 0x4B$at OrganizationSdkServiceInternal.Create(Entity entity, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, Dictionary`2 optionalParameters)  ilOffset = 0x0$at CrmODataExecutionContext.Create(Entity entity)  ilOffset = 0x0$at CrmODataServiceDataProvider.CreateEdmEntity(CrmODataExecutionContext context, String edmEntityName, EdmEntityObject entityObject, Boolean isUpsert)  ilOffset = 0xE$at EntityController.PostEntitySet(String entitySetName, EdmEntityObject entityObject)  ilOffset = 0x0$at   ilOffset = 0xFFFFFFFF$at <>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)  ilOffset = 0x0$at ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)  ilOffset = 0x34$at <InvokeActionAsyncCore>d__0.MoveNext()  ilOffset = 0x52$at AsyncTaskMethodBuilder`1.Start(TStateMachine& stateMachine)  ilOffset = 0x2C$at ApiControllerActionInvoker.InvokeActionAsyncCore(HttpActionContext actionContext, CancellationToken cancellationToken)  ilOffset = 0x35$at ApiControllerActionInvoker.InvokeActionAsync(HttpActionContext actionContext, CancellationToken cancellationToken)  ilOffset = 0x3$at <ExecuteAsync>d__2.MoveNext()  ilOffset = 0xD9$at AsyncTaskMethodBuilder`1.Start(TStateMachine& stateMachine)  ilOffset = 0x2C$at ActionFilterResult.ExecuteAsync(CancellationToken cancellationToken)  ilOffset = 0x35$at ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)  ilOffset = 0x138$at <SendAsync>d__1.MoveNext()  ilOffset = 0x123$at AsyncTaskMethodBuilder`1.Start(TStateMachine& stateMachine)  ilOffset = 0x2C$at HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0x3D$at HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0x3C$at HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0xBF$at DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0x19$at <SendAsync>d__0.MoveNext()  ilOffset = 0x17D$at AsyncTaskMethodBuilder`1.Start(TStateMachine& stateMachine)  ilOffset = 0x2C$at CorsMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0x3D$at DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0x19$at <SendAsync>d__0.MoveNext()  ilOffset = 0x50$at AsyncTaskMethodBuilder`1.Start(TStateMachine& stateMachine)  ilOffset = 0x2C$at CrmETagMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0x3D$at DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0x19$at <SendAsync>d__0.MoveNext()  ilOffset = 0xF$at AsyncTaskMethodBuilder`1.Start(TStateMachine& stateMachine)  ilOffset = 0x2C$at CrmDelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0x3D$at DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0x19$at <SendAsync>d__0.MoveNext()  ilOffset = 0x11D$at AsyncTaskMethodBuilder`1.Start(TStateMachine& stateMachine)  ilOffset = 0x2C$at HttpServer.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0x3D$at HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)  ilOffset = 0x3C$at <ProcessRequestAsyncCore>d__0.MoveNext()  ilOffset = 0x96$at AsyncTaskMethodBuilder.Start(TStateMachine& stateMachine)  ilOffset = 0x2C$at HttpControllerHandler.ProcessRequestAsyncCore(HttpContextBase contextBase)  ilOffset = 0x2C$at TaskAsyncHelper.BeginTask(Func`1 taskFunc, AsyncCallback callback, Object state)  ilOffset = 0xD$at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  ilOffset = 0xE1$at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  ilOffset = 0x3C$at PipelineStepManager.ResumeSteps(Exception error)  ilOffset = 0x27A$at HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)  ilOffset = 0x31$at HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)  ilOffset = 0xB0$at PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)  ilOffset = 0x131$at PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)  ilOffset = 0x0    

    Anyone had this before? Is there a way I could get a more explicit error message?

    Thanks

    Guillaume

    Monday, September 12, 2016 12:34 PM

All replies

  • I am not sure if the User creation via tools will be possible, because when you create manually from  UI, the domain AD information are synced to user record in CRM and a relationship is created internally with AD user, and this exactly happens with on change of username field.

    Not sure if the above statement is fully correct.


    If my response answered your question, please "mark the response as an answer" and also "vote as helpful". Regards, Hari. www.crm2011byhari.blogspot.com

    Tuesday, September 13, 2016 5:31 AM