Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Why am I getting this error: The name 'XXXXX' does not exist in the current context

$
0
0

Okay, so I have an application that calls from the same API on multiple activities. Since I don't want to rewrite the code for the RestRequest, I tried placing it all in one unique class so that I could just call for the async tasks as needed.

But when I try to implement the await call, I get an error saying that the function name doesn't exist in context. Could someone help me figure this out?

ViewModel.cs (where the function is being called - it's in another task that's called from a button command):

public async Task ExecuteLoadItemDetailsCommand()
    {
        if (IsBusy)
            return;

        IsBusy = true;

        try
        {
            Items.Clear();
            await PostItemCompleteReq("330", "999989", "476");     // Stupid error... HALP!
            Items.Add(item);
            Debug.WriteLine("Items Size Is: " + Items.Count);

        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }
        finally
        {
            IsBusy = false;
        }
    }

Then for the function I'm trying to call, it used to be set as a private async task in the ViewModel class, but after trying to separate it out I get the error, but here's the code for the API call.

BuildRestAccess.cs (where I'll have multiple functions using the same restClient object).

public class BuildRestAccess
{

    private const string BaseHackApi = "https://xxx.xxxxxx.xxx";
    private string BaseAuthCode = Application.Current.Properties["auth_token"] as string;
    RestClient restClient = new RestClient(BaseHackApi);

    public async Task<ItemCompleteDetail> PostItemCompleteReq(string warehouse, string customer, string location)
    {
        var customerDetails = new ItemSearchRequest
        {
            WarehouseNumber = warehouse,
            CustomerNumber = customer,
            LocationNumber = location
        };
        restClient.UseSerializer(() => new JsonNetSerializer());
        restClient.AddDefaultHeader("Content-type", "application/json");
        var restRequest = new RestRequest("1/items/complete/{itemNumber", Method.POST);
        restRequest.AddHeader("Authorization", BaseAuthCode);
        restRequest.AddParameter("itemNumber", "1525252", ParameterType.UrlSegment);
        restRequest.AddJsonBody(customerDetails);

        var cancellationToken = new CancellationTokenSource();
        var itemReturn = await restClient.ExecuteTaskAsync(restRequest, cancellationToken.Token);

        //Debug Code
        Debug.WriteLine("REST DATA IS: " + restClient.BuildUri(restRequest));
        Debug.WriteLine("REST RETURN IS: " + itemReturn.ResponseStatus + " Status: " + itemReturn.StatusCode + "/" + itemReturn.StatusDescription);

        ItemCompleteDetail allItemDeets = JsonConvert.DeserializeObject<ItemCompleteDetail>(itemReturn.Content);
        return allItemDeets;
    }

}

Anyone have a thought? Am I just missing something obvious?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>