none
[BUG] Task InsertAsync(T instance, IDictionary<string, string> parameters) doesn't work on Android RRS feed

  • Question

  • Hello,

    I use Xamarin with the azure-mobile-service lib.

    I have a problem with that : I want to call this method :

    Task InsertAsync(T instance, IDictionary<string, string> parameters)

    Here is my code :

    private readonly IMobileServiceTable<Product> table; 
    
    [...]
    
    Product p = new Product(...); 
    IDictionary<string, string> parameters = new Dictionary<String, String>();parameters.Add("test", "test"); 
    var task = this.table.InsertAsync(p, parameters);

    Before I compile, I don't have any error.

    And when I compile, I have an error :

    The best overload method 'Microsoft.WindowsAzure.MobileServices.IMobileServiceTable.InsertAsync(Windows.Data.Json.JsonObject, System.Collections.Generic.IDictionary<string,string>)' have invalid arguments 
    Argument 1 : Impossible to convert 'Catalog.Core.Business.Product' into 'Windows.Data.Json.JsonObject'

    (translated from french to english so content of error can be a bit different)

    I suppose that it's a bug in the lib because the interface 

            Task InsertAsync(T instance, IDictionary<string, string> parameters);

    exists into azure-mobile-services\sdk\windows\src\Microsoft.Azure.Zumo.Windows.Managed\Core\IMobileServiceTable.Generic.cs

    In addition, this code work very well on WinRT !

    Thanks !


    Thursday, June 20, 2013 3:17 PM

Answers

All replies

  • Hi The,

    It seems like the issue is the definition of your class Product.

    You did not include that code so I am not sure what the problem could be.

    -Jeff


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Friday, June 21, 2013 12:17 PM
  • If the problem is the product class, why on WinRT i don't have any problem ?

    Here is my code :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    using System.ComponentModel;
    using System.IO;
    
    using Catalog.Core.Tools;
    using System.Runtime.Serialization;
    using Microsoft.WindowsAzure.MobileServices;
    
    namespace Catalog.Core.Business
    {
    
        /// <summary>
        /// Describe the object Product in the azure database
        /// </summary>
    
        [DataTable(Name = "product")]
        public class Product : INotifyPropertyChanged, IComparable, IEquatable<Product>
        {
    
            #region EVENTS
    
            public event PropertyChangedEventHandler PropertyChanged;
    
            // Create the OnPropertyChanged method to raise the event 
            protected void OnPropertyChanged(string name)
            {
                PropertyChangedEventHandler handler = PropertyChanged;
                if (handler != null)
                {
                    handler(this, new PropertyChangedEventArgs(name));
                }
    
            }
            #endregion
    
    
            #region ATTRIBUTES
    
            /// <summary>
            /// Gets or sets the id.
            /// </summary>
            /// <value>
            /// The id.
            /// </value>
            [DataMember(Name = "id")]
            public int Id { get; set; }
    
            /// <summary>
            /// Gets or sets the name.
            /// </summary>
            /// <value>
            /// The name.
            /// </value>
            [DataMember(Name = "name")]
            public String Name { get; set; }
    
            /// <summary>
            /// Gets or sets the description.
            /// </summary>
            /// <value>
            /// The description.
            /// </value>
            [DataMember(Name = "description")]
            public String Description { get; set; }
    
            /// <summary>
            /// Gets or sets the width.
            /// </summary>
            /// <value>
            /// The width.
            /// </value>
            [DataMember(Name = "width")]
            public Decimal Width { get; set; }
    
            /// <summary>
            /// Gets or sets the height.
            /// </summary>
            /// <value>
            /// The height.
            /// </value>
            [DataMember(Name = "height")]
            public Decimal Height { get; set; }
    
            /// <summary>
            /// Gets or sets the depth.
            /// </summary>
            /// <value>
            /// The depth.
            /// </value>
            [DataMember(Name = "depth")]
            public Decimal Depth { get; set; }
    
            /// <summary>
            /// Gets or sets the dimensions unit.
            /// </summary>
            /// <value>
            /// The dimensions unit.
            /// </value>
            [DataMember(Name = "dimensionsUnit")]
            public String DimensionsUnit { get; set; }
    
            /// <summary>
            /// Gets or sets the weight.
            /// </summary>
            /// <value>
            /// The weight.
            /// </value>
            [DataMember(Name = "weight")]
            public Decimal Weight { get; set; }
    
            /// <summary>
            /// Gets or sets the weight unit.
            /// </summary>
            /// <value>
            /// The weight unit.
            /// </value>
            [DataMember(Name = "weightUnit")]
            public String WeightUnit { get; set; }
    
            /// <summary>
            /// Gets or sets the price.
            /// </summary>
            /// <value>
            /// The price.
            /// </value>
            [DataMember(Name = "price")]
            public Decimal Price { get; set; }
    
            /// <summary>
            /// Gets or sets the small pic.
            /// </summary>
            /// <value>
            /// The small pic.
            /// </value>
            [DataMember(Name = "smallPic")]
            public String SmallPic { get; set; }
    
            /// <summary>
            /// Gets or sets the big pic.
            /// </summary>
            /// <value>
            /// The big pic.
            /// </value>
            private String bigpic;
            [DataMember(Name = "bigPic")]
            public String BigPic
            {
                get
                {
                    if (HasImage && bigpic == null)
                    {
                        // the picture is available, but not loaded : we load it !
                        IoC.Resolve<IProductManager>().GetBigPicProductAsync(this);
                    }
                    // if already available, we return it, or we return null = for the converter : no pic !
                    return bigpic;
                }
                set
                {
                    if (bigpic != value)
                    {
                        bigpic = value;
                        OnPropertyChanged("BigPic");
                    }
                }
            }
    
    
            /// <summary>
            /// Gets or sets the added time.
            /// </summary>
            /// <value>
            /// The added time.
            /// </value>
            [DataMember(Name = "addedTime")]
            public int AddedTime { get; set; }
    
            private bool isFavorite;
            [DataMember(Name = "isFavorite")]
            public bool IsFavorite
            {
                get { return isFavorite; }
                set
                {
                    if (isFavorite != value)
                    {
                        isFavorite = value;
                        OnPropertyChanged("IsFavorite");
                    }
                }
            }
    
            public bool HasImage { get { return (SmallPic != null); } }
    
    
            public String FormatDimensions { get { return this.Width + "x" + this.Height + "x" + this.Depth + this.DimensionsUnit; } }
            public String FormatWeight { get { return this.Weight + this.WeightUnit; } }
            public String FormatAddedTime { get { return Tools.DateSystem.UnixTimeStampToDateTime(this.AddedTime).ToString(); } }
    
    
            #endregion
    
    
            #region CONSTRUCTOR
    
            /* DO NOT REMOVE - SERIALIZATION */
            public Product() { }
    
            public Product(Product original)
            {
                this.Id = original.Id;
                this.Name = original.Name;
                this.Description = original.Description;
                this.Width = original.Width;
                this.Height = original.Height;
                this.Depth = original.Depth;
                this.DimensionsUnit = original.DimensionsUnit;
                this.Weight = original.Weight;
                this.WeightUnit = original.WeightUnit;
                this.Price = original.Price;
                this.SmallPic = original.SmallPic;
                this.BigPic = original.BigPic;
                this.AddedTime = original.AddedTime;
                this.IsFavorite = original.IsFavorite;
    
            }
    
    
            /// <summary>
            /// Initializes a new instance of the <see cref="Product"/> class.
            /// </summary>
            /// <param name="name">The name.</param>
            /// <param name="description">The description.</param>
            /// <param name="width">The width.</param>
            /// <param name="height">The height.</param>
            /// <param name="depth">The depth.</param>
            /// <param name="dimensionsUnit">The dimensions unit.</param>
            /// <param name="weight">The weight.</param>
            /// <param name="weightUnit">The weight unit.</param>
            /// <param name="price">The price.</param>
            /// <param name="smallPic">The small pic.</param>
            /// <param name="bigPic">The big pic.</param>
            /// <param name="addedTime">The added time.</param>
            /// <exception cref="System.IndexOutOfRangeException">
            /// Invalid price
            /// or
            /// Invalid weight
            /// or
            /// Invalid width
            /// or
            /// Invalid height
            /// or
            /// Invalid depth
            /// </exception>
            public Product(int id, String name, String description, Decimal width, Decimal height, Decimal depth, String dimensionsUnit, Decimal weight, String weightUnit, Decimal price, String smallPic, String bigPic, int addedTime, bool isFav)
            {
                this.Id = id;
                this.Name = name;
                this.Description = description;
                this.Width = width;
                this.Height = height;
                this.Depth = depth;
                this.DimensionsUnit = dimensionsUnit;
                this.Weight = weight;
                this.WeightUnit = weightUnit;
                this.Price = price;
                this.SmallPic = smallPic;
                this.BigPic = bigPic;
                this.AddedTime = addedTime;
                this.IsFavorite = isFav;
            }
    
    
    
    
            #endregion
    
    
    
            public int CompareTo(object obj)
            {
    
                if (((Product)obj).Id == this.Id)
                    return 0;
                else if (((Product)obj).Id > this.Id)
                    return -1;
                else
                    return 1;
    
            }
    
    
            public bool Equals(Product other)
            {
                return (other.Id == this.Id);
            }
    
            public override bool Equals(object obj)
            {
                return (((Product)obj).Id == this.Id);
            }
    
            public override int GetHashCode()
            {
                return this.Id;
            }
        }
    }

    Friday, June 21, 2013 1:12 PM
  • Hi,

    I can confirm this is a bug. The problem is that the Android version of this interface was not updated when custom parameters were added. You can see that the overload is missing from this file:

    https://github.com/xamarin/azure-mobile-services/blob/master/sdk/xamarin/android/src/Microsoft.Azure.Zumo.Android/Core/IMobileServiceTable.Generic.cs

    The Xamarin folks are looking into the issue. I'll update this thread when I have more info.

    Paul

    Saturday, June 22, 2013 12:20 AM
    Moderator
  • Thanks, I hope that they will fix this soon.
    Monday, June 24, 2013 2:26 PM