Xero-NetStandard icon indicating copy to clipboard operation
Xero-NetStandard copied to clipboard

Method not found: 'Void RestSharp.RestRequest..ctor(RestSharp.Method)'.

Open pradeepinfotechi opened this issue 3 years ago • 1 comments

Xero.Netstandard.OAuth2.Client - 1.6 Xero.Netstandard.OAuth2 - 3.29

Resthsharp - 108. 0.1.0 Also tried with 108.0.2.0

Authorization is getting successful and later when try to create invoice using async method gets error

Method not found: 'Void RestSharp.RestRequest..ctor(RestSharp.Method)'.

Earlier used with Restsharp 106.X version, we didn't had any issue. Due to other features we have upgraded Restsharp later xero integration stopped working with above issue.

Sample Code below

In line var xeroResp = await AccountingApi.CreateInvoicesAsync(accessToken, t.TenantId.ToString(), objInvoices); // we get the issue.

public async Task GetTenants(string code) { LoggerMethodName = "Method: GetTenants"; strErrMsg = string.Empty; bool result = false; try { var tenantList = new List<Tenant>(); using (var client = new HttpClient()) { var response = await client.RequestAuthorizationCodeTokenAsync(new AuthorizationCodeTokenRequest { Address = "https://identity.xero.com/connect/token", GrantType = "code", Code = code, ClientId = xeroConfiguration.ClientId, ClientSecret = xeroConfiguration.ClientSecret, RedirectUri = xeroConfiguration.CallbackUri.ToString(), Parameters = { { "scope", xeroConfiguration.Scope} } });

                if (response.IsError)
                {
                    strErrMsgLink = response.Error;
                    throw new Exception(response.Error);
                }
                var accessToken = response.AccessToken;
                var refreshToken = response.RefreshToken;
                var identityToken = response.IdentityToken;
                string tenant;
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                using (var requestMessage = new HttpRequestMessage(System.Net.Http.HttpMethod.Get, "https://api.xero.com/connections"))
                {
                    HttpResponseMessage httpResult = client.SendAsync(requestMessage).Result;
                    System.Console.WriteLine(httpResult.RequestMessage);
                    tenant = httpResult.Content.ReadAsStringAsync().Result;
                    tenantList = JsonConvert.DeserializeObject<List<Tenant>>(tenant);
                }

                foreach (Tenant t in tenantList)
                {
                    Invoices objInvoices = new Invoices();
                    List<Invoice> xinvoices = new List<Invoice>();
                    xinvoices.Add(PrepareInvoiceObj());

                    if (xinvoices.Count > 0)
                    {
                        objInvoices._Invoices = xinvoices;
                        var AccountingApi = new AccountingApi();
                        var xeroResp = await AccountingApi.CreateInvoicesAsync(accessToken, t.TenantId.ToString(), objInvoices); // Creating the Invoice In XERO
                    }
                    else
                    {
                        strErrMsgLink = "Xero Invoice object is empty";
                        break;
                    }
                }
                strErrMsgLink = string.Empty;
                result = true;
            }
        }
        catch (Exception ex)
        {
            Logging
        }
        return result;
    }

pradeepinfotechi avatar Oct 06 '22 06:10 pradeepinfotechi

Hi @pradeepinfotechi

I am taking a look and trying to reproduce this particular error. I haven't been able to yet but in the meantime, could I ask you to keep the version as 108.0.1 and try clear your nuget cache and re-running your project. Does the error persist?

dotnet nuget locals all --clear
dotnet clean
dotnet build
dotnet run

Abhisha1 avatar Oct 07 '22 00:10 Abhisha1