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

Could not find method due to a type load error

$
0
0

Hello guys,

I'm facing a problems to run my project in just in IOS system, it is running normally on Android.
I created a generic class called Restful.cs to warrant access for all kind of viewmodel results on my web api, but when my application calls a method that contains a restful object class instance, the application crashes:

{System.TypeLoadException: Could not find method due to a type load error
at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.10.0.36/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:84
at MLL_Partner.View.Login.LoginSystem() [0x00013] in :0
at MLL_Partner.View.Login.ButtonAccess_Clicked (System.Object sender, System.EventArgs e) [0x00002] in C:\Visual Studio Projects\MLL\Mobile\MLL_Partner\MLL_Partner\View\Login.xaml.cs:46 }

Follow my method call:

private void ButtonAccess_Clicked(object sender, EventArgs e)
{
try
{
Login();
}
catch (Exception ex)
{
DisplayAlert("Erro", ex.Message, "Exit");
}
}
private async void LoginSystem()
{
IsBusy = true;
var restLogin = new RestfulClient(ViewModel.Session.BaseAddress, ViewModel.Session.Token);
resp = await restLogin.Login(String.Format("api/security/token"), entryUserName.Text, entryPassword.Text);
....
}

Follow my restful class:

public class RestfulClient
{
private HttpClient _httpClient { get; set; }
public RestfulClient(String pBaseAddress, String pToken)
{
_httpClient = new HttpClient();
_httpClient.BaseAddress = new Uri(pBaseAddress);
_httpClient.Timeout = new TimeSpan(0, 0, 30);
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", pToken);
}
public async Task Login(string tokenRequestUrl, string username, string password)
{
HttpResponseMessage response = new HttpResponseMessage();
TokenResponseViewModel actionResult = new TokenResponseViewModel();

        var prms = new List<KeyValuePair<string, string>>
        {
            new KeyValuePair<string, string>("grant_type", "password"),
            new KeyValuePair<string, string>("username", username),
            new KeyValuePair<string, string>("password", password)
        };

        response = await _httpClient.PostAsync(tokenRequestUrl, new FormUrlEncodedContent(prms));
        var resp = await response.Content.ReadAsStringAsync();
        var dataResult = JsonConvert.DeserializeObject<TokenResponseViewModel>(resp);
        dataResult.Username = username;
        return actionResult;
    }

    public async Task<ActionResultViewModel<T>> GetAsync(String requestURI)
    {
        ActionResultViewModel<T> actionResult;
        try
        {
            var resp = await _httpClient.GetAsync(requestURI);
            if (resp.IsSuccessStatusCode)
            {
                var respStr = await resp.Content.ReadAsStringAsync();
                actionResult = JsonConvert.DeserializeObject<ActionResultViewModel<T>>(respStr);
                actionResult.LOGIN = false;

                return actionResult;
            }
            else
            {
                if(resp.ReasonPhrase == "Unauthorized" || resp.ReasonPhrase == "Not Found")
                    actionResult = new ActionResultViewModel<T> { MESSAGE = "Favor refazer o login!", DATA = Activator.CreateInstance<T>(), OK = false, LOGIN = true };
                else
                    actionResult = new ActionResultViewModel<T> { MESSAGE = "Erro desconhecido, favor verificar sua conexão com a internet!", DATA = Activator.CreateInstance<T>(), OK = false };
            }
        }
        catch (Exception e)
        {
            actionResult = new ActionResultViewModel<T> { MESSAGE = "Favor verificar sua conexão com a internet!", DATA = Activator.CreateInstance<T>(), OK = false };
        }

        return actionResult;
    }

Someone could help me to fix that problem?

Thank you guys


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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