locked
A method was called at an unexpected time. RRS feed

  • Question

  • I am trying to consume web api service:

    An exception of type 'System.InvalidOperationException' occurred in abc.exe but was not handled in user code

    WinRT information: This is not a string value. Use ValueType property to get the type.

    Additional information: A method was called at an unexpected time.

    If there is a handler for this exception, the program may be safely continued.

    • Edited by rsunilkumar Wednesday, September 25, 2013 12:14 PM
    Wednesday, September 25, 2013 12:14 PM

All replies

  • Look at the line of code where the exception was raised. It sounds like one of the arguments is incorrect: "WinRT information: This is not a string value. Use ValueType property to get the type"

    If you need more specific help you'll need to provide more details: what is the code that fails?

    --Rob

    Wednesday, September 25, 2013 2:13 PM
    Moderator
  • here is my code, in the italic bold area am getting this error

    var serviceuri = "api controller comes here";
                var client = new System.Net.Http.HttpClient();
                client.BaseAddress = new Uri("service link comes here");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var response = await client.GetAsync(serviceuri);
                if (response.IsSuccessStatusCode)
                {
                    var data = await response.Content.ReadAsStringAsync();
                    var contacts = JsonArray.Parse(data);

                    try
                    {

                        var qry = from m in contacts
    select new
                                  {
                                      Id = m.GetObject()["Id"].GetString(),
                                      JobTitle = m.GetObject()["JobTitle"].GetString(),
                                      Location = m.GetObject()["Location"].GetString(),
                                      JobDescription = m.GetObject()["JobDescription"].GetString(),
                                      CreatedDate = m.GetObject()["CreatedDate"].GetString(),

                                  };
                        listview1.ItemsSource = qry;
                    }
                    catch (Exception ex)
                    {

                    }

                                                                    
    Wednesday, September 25, 2013 2:38 PM
  • Id is not a string, so you can't call GetString on it. Try using:

    Id = m.GetObject()["Id"].ValueType

    Robert

    Wednesday, November 27, 2013 1:37 AM