XeroAPI / Xero-NetStandard

A wrapper of the Xero API in the .NetStandard 2.0 framework. Supports Accounting, Payroll AU/US, and Files
MIT License
126 stars 124 forks source link

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

Open pradeepinfotechi opened 2 years ago

pradeepinfotechi commented 2 years ago

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(); 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;
    }
Abhisha1 commented 2 years ago

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