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

Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0' #387

Open attilaTM opened 3 years ago

attilaTM commented 3 years ago

Unfortunately, I have to redo our Xero integration because it uses an old SDK (Xero.NET - not Oauth 2) which will stop working soon. It is quite uncomfortable that everything has to be redone from scratch and the old code cannot be reused. You should have designed the new API that way that the old integration code can be reused after some minor adjustments. Anyway, I want to report a different issue. I need the new SDK to work with a .NET framework application. I have created a sample app (.NET framework 4.7.2) for testing. Regardless whatever I try I have this error

Server Error in '/' Application.


Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

This seems to be a version conflict which is not present in .Net core applications. If I download the https://github.com/XeroAPI/Xero-NetStandard-custom-connections-starter sample application that one doesn’t have this issue. For some reason there is no .NET framework sample app to download, only .Net core ones. Is it because the SDK is not compatible with .Net framework? Can this version conflict be fixed in my .NET framework app?

The code I am trying to execute is Xero.NetStandard.OAuth2.Config.XeroConfiguration xconfig = new Xero.NetStandard.OAuth2.Config.XeroConfiguration(); xconfig.ClientId = "yourClientId"; xconfig.ClientSecret = "yourClientSecret"; xconfig.CallbackUri = new Uri("https://localhost:5001"); //default for standard webapi template xconfig.Scope = "openid profile email offline_access files accounting.transactions accounting.contacts";

        var client = new Xero.NetStandard.OAuth2.Client.XeroClient(xconfig);
        var xeroToken = await client.RequestClientCredentialsTokenAsync();

        var contact = new Xero.NetStandard.OAuth2.Model.Accounting.Contact();
        contact.Name = "John Smith";

        var line = new Xero.NetStandard.OAuth2.Model.Accounting.LineItem()
        {
            Description = "A golf ball",
            Quantity = 12,
            UnitAmount = (decimal?)5.12,
            AccountCode = "200"
        };

        var lines = new List<Xero.NetStandard.OAuth2.Model.Accounting.LineItem>() {
          line
        };

        var invoice = new Xero.NetStandard.OAuth2.Model.Accounting.Invoice()
        {
            Type = Xero.NetStandard.OAuth2.Model.Accounting.Invoice.TypeEnum.ACCREC,
            Contact = contact,
            Date = DateTime.Today,
            DueDate = DateTime.Today.AddDays(30),
            LineItems = lines
        };

        var invoiceList = new List<Xero.NetStandard.OAuth2.Model.Accounting.Invoice>();
        invoiceList.Add(invoice);

        var invoices = new Xero.NetStandard.OAuth2.Model.Accounting.Invoices();
        invoices._Invoices = invoiceList;

        var AccountingApi = new Xero.NetStandard.OAuth2.Api.AccountingApi();
        var response = await AccountingApi.CreateInvoicesAsync(xeroToken.AccessToken, xeroToken.Tenants[0].TenantId.ToString(), invoices);
BTPDarren commented 3 years ago

You could take a look at my wrapper

https://github.com/AGenius/Xero.Net.OAuth2