locked
Problem insertasync xamarin azure mobile service RRS feed

  • Question

  • Hello,

    I use Xamarin Azure Mobile Service (https://github.com/xamarin/azure-mobile-services). I have a string to insert. it can contains some lines ( \r\n on winRT or \n on android ).

    For example, for the following text :

    "this is a test"

    on WinRT, the string is "this is\r\na test" => insert ok

    on Android, the string is "this is\na test" => insert ko, I don't have any message from azure, no logs, nothing !

    If i remplace \n by \r\n, still same proble => KO

    If i try to "hash" the \n (\n) => insert ok, but when i get back the string, is \n ! So of course it doesn't work when I want to display it

    Because is a cross platform project, I really don't want to - hash all the string - do some platform specific thing to manage that ( especially about the fact that my winRT \r\n is displayed correctly on my android device)

    The maximum trick that I can do is to convert \n to \r\n (because I'm afraid about \n under winRT ....) but it still doesn't work.

    Conclusion : it seems that the android lib (maybe iOS ?) have a bug on the insertion on Azure, can you tell me more informations about that or try to fix it, thanks !

    Thursday, May 2, 2013 7:45 AM

Answers

  • Hi Dahevos,

    I've isolated the problem. There is a bug in our Android component where it does not appropriately escape newlines when it generates JSON to send to the server

    As a workaround until the bug is fixed, can you try using the following ServiceFilter to correct the problem? You would register this ServiceFilter only in the android version of your application:

    public class NewLineServiceFilter : IServiceFilter { public System.Threading.Tasks.Task<IServiceFilterResponse> Handle (IServiceFilterRequest request, IServiceFilterContinuation continuation) {

    if(request.Content != null) request.Content = request.Content.Replace ("\n", "\\r\\n"); return continuation.Handle (request); } } var client = new MobileServiceClient("url","key").WithFilter(new NewLineServiceFilter());

    I tried this across both WinRT and Android and it seems to work well in both cases. It would be great if you could give this a go and let me know if you run into any problems.

    We will of course fix the bug so that you can remove this workaround at a later date.

    Paul




    • Marked as answer by Dahevos Friday, May 3, 2013 7:50 AM
    • Edited by Paul Batum Monday, May 6, 2013 4:06 PM
    Friday, May 3, 2013 1:49 AM

All replies

  • Thanks Dahevos, let us take a look - obviously there are differences on handling line breaks between OS's. We'll get back to you shortly.

    Thursday, May 2, 2013 1:00 PM
  • Hi Dahevos,

    I've been able to reproduce the error. I think the problem is client side and that the request is never sent to the server. I'm still investigating and will let you know once I know more.

    Paul

    Friday, May 3, 2013 12:22 AM
  • Hi Dahevos,

    I've isolated the problem. There is a bug in our Android component where it does not appropriately escape newlines when it generates JSON to send to the server

    As a workaround until the bug is fixed, can you try using the following ServiceFilter to correct the problem? You would register this ServiceFilter only in the android version of your application:

    public class NewLineServiceFilter : IServiceFilter { public System.Threading.Tasks.Task<IServiceFilterResponse> Handle (IServiceFilterRequest request, IServiceFilterContinuation continuation) {

    if(request.Content != null) request.Content = request.Content.Replace ("\n", "\\r\\n"); return continuation.Handle (request); } } var client = new MobileServiceClient("url","key").WithFilter(new NewLineServiceFilter());

    I tried this across both WinRT and Android and it seems to work well in both cases. It would be great if you could give this a go and let me know if you run into any problems.

    We will of course fix the bug so that you can remove this workaround at a later date.

    Paul




    • Marked as answer by Dahevos Friday, May 3, 2013 7:50 AM
    • Edited by Paul Batum Monday, May 6, 2013 4:06 PM
    Friday, May 3, 2013 1:49 AM
  • This "fix" create Exception "Object reference not set to an instance of an object" when I get all my existing data. 

    This bug is not critical actually for my application, I will wait until this bug is fixed.

    Thanks for your answer.

    Friday, May 3, 2013 7:49 AM
  • Hi Dahevos,

    The first version I posted was missing a null check. I have updated my post above to include the null check, perhaps it will work better for you.

    I will update this thread when the bug itself is fixed.

    Monday, May 6, 2013 4:07 PM
  • I come again in order to notice you that iOS have also an error while trying insert \t (tabulation) or \n (new line).

    Hope that it will be fixed (with android version) soon.

    Thanks.

    Monday, May 20, 2013 9:00 AM
  • The Mobile Services component for Xamarin has been updated (version 1.1.0) and should longer have any of the issues. Please let me know if you encounter any of the above issues when using the new version of the component.
    Wednesday, December 18, 2013 11:13 PM