Error when creating user via REST API

Error when creating user via REST API

This question has suggested answer(s)

The user gets created in the Telligent Community, but the error message indicates there was an auxiliary function that did not happen properly, which in turn, doesn't send back a 200 (OK) status code. 

After using the v2 debug console, the problem appears to occur in the Telligent.Evolution.Messages assembly. The exception is a FormatException: Input string was not in a correct format.

It is noteworthy that this only happens in one client environment. Other environments for the same client work properly. Even other clients in the same environment work properly. All dll files are identical across clients and across environments.

I found a workaround for the error under "Membership Administration --> Configuration --> Account Settings --> New User Experience". Set "Deliver Welcome Message" to "No". When this is set to no, we get a 200 HTTP response. Obviously, we might not want this as a long-term solution, if we want to deliver an email to the new user, however.

Stack trace is:

[FormatException]: Input string was not in a correct format.
   at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
   at System.String.Format(IFormatProvider provider, String format, Object[] args)
   at System.String.Format(String format, Object arg0, Object arg1, Object arg2)
   at Telligent.Evolution.Messages.NewUserWelcomeMessageModule.(User user, CSEventArgs e)
   at Telligent.Evolution.Components.CSUserEventHandler.Invoke(User user, CSEventArgs e)
   at Telligent.Evolution.Components.CSApplication.ExecuteUserEvent(Object EventKey, User user, ObjectState state, ApplicationType appType)
   at Telligent.Evolution.Components.UserDataService.Create(User user, Boolean sendEmail, Boolean ignoreDisallowNames, Boolean createLocalUserOnly)
   at Telligent.Evolution.Components.UserDataService.Create(User user, Boolean sendEmail)
   at Telligent.Evolution.Components.UserService.Create(User user, Boolean sendEmail)
   at Telligent.Evolution.Rest.Resources.Users.UserService.CreateUser(RestUser restUser)
   at Telligent.Evolution.Rest.Resources.Users.UserController.Create(UserCreateRequest request)
[TargetInvocationException]: Exception has been thrown by the target of an invocation.
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Telligent.Evolution.Rest.Infrastructure.ActionBinding.Invoke(IController target, IRestRequest request)
   at Telligent.Evolution.Rest.Infrastructure.ActionDispatcher.ProcessRequest(RequestContext context, IActionBinding binding)
   at Telligent.Evolution.Rest.Infrastructure.RestHttpHandler.ProcessRequest()
   at Telligent.Evolution.Rest.Infrastructure.RestHttpHandler.?(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
All Replies
  • In that same page, can you check the welcome message body?  From the error it looks like it's formatted in a way that is confusing to the code.  It will insert the user's display name, a link to edit their profile, and a  link to their profile in place of {0}, {1}, and {2} respectively.  Verify you don't have anything like {3} or higher as the software won't know what to do with that and will return that error.

    Also, if you are using any curly braces other than the ones described earlier, you'll need to double them.  So if you wanted the email to say something like "{brace yourself} for an awesome experience" you would need to put "{{brace yourself}} for an awesome experience" and it would be converted to just single braces when sent.

    That's a brief rundown of what might be the problem.  For more detailed info, you can check out this site.  For reference, here's the default welcome message:

    {0}, while browsing the community, don't forget to visit your {2}, which you can customize to include the information that is most important to you. Be sure to {1} to introduce yourself to the community.

    Happy connecting!

  • i don't think this is my code. the error exists inside the "Telligent.Evolution.Messages" assembly. So my guess is that code, under this circumstance, follows some structural "if" path that has an incorrect string.format() sequencing of braces and represented variables. the specific type in the stack trace appears to be "NewUserWelcomeMessageModule".

    ------------------

    The message in the content area is default otb:

    {0}, while browsing the community, don't forget to visit your {2}, which you can customize to include the information that is most important to you. Be sure to {1} to introduce yourself to the community.

    Happy connecting!

    {0} is replaced with the user's display name

    {1} links to the user's edit page

    {2} links to the profile

    ------------------

    we are creating the users without a display name, but also setting it to not use a display name as well. shouldn't that be trapped in the code to insert string.Empty or the username if null? do you think that's the problem?

  • Yea, I don't think it's any custom code.  The error is coming from the string.Format() method which uses the welcome message body as to format the rest of the message.  Not setting the display name is fine, it falls back to the username.  You're using the OOTB message?

    This blog post contains an example of what might be the problem and how to fix it. blogs.thesitedoctor.co.uk/.../StringFormat+And+Input+String+Was+Not+In+A+Correct+Format+Error.aspx

  • i am using the OOTB message. there aren't any braces even in the merged values.

  • Can you try removing all the {#}'s from the message and trying to create a user?  Then, if that works, add them back in one by one and let me know when it works and when it doesn't?

  • nope. i can take all of the braces out and just put in test! and it still fails.

    after a quick decompile of that assembly I would have some concerns about the lines in the screenshot provided.

  • Hmm, then maybe it's not with the welcome message body.

    Those are CreateNewAccount_EditProfileLink and CreateNewAccount_NewUserMessage_Home in your Web\Languages\en-US\Resources.xml file.

  • interesting. the values of those two keys are inconsequential to the string.Format().

    and this key: CreateNewAccount_NewUserMessage is what the text box uses by default, i suppose.

    i see in the code it does have a total of 3 parameters passed to the final string.format....but i have no clue what the result of "arg1" and "arg2" is supposed to look like.

  • arg1 and arg2 are hyperlinks to the user profile and site home page respectively but their values shouldn't cause an error in the last string.Format().

    What version are you running?

  • Platform version: 6.0.119.19092

  • any help here?

  • I'm looking through the code and I'm really at a loss for what could be causing the problem.  Maybe do a select-all in the welcome message box, delete everything, and then put just "test" in there.  Maybe there is some text that is hiding in the box that's causing a problem. :-/

  • i tried exactly that and it still failed.