I’ve borrowed some code from another question and answer online (accepted as a working solution), but my compiler seems to expect some extra characters and I can’t see why.
Compiler is expecting all of this:
Line: 37 - ) expected
Line: 37 - ; expected
Line: 37 - Invalid expression term ')'
Line: 37 - ; expected
at the line:
if (ex is Avalara.AvaTax.RestClient.AvaTaxError avaTaxError)
in the code block below
using System;
using SAPbobsCOM;
using SAPbouiCOM;
using Avalara.AvaTax.RestClient;
namespace B1UPCODE
{
public class B1UPCLASS
{
public void DynamicCode(params object[] parameters)
{
SAPbobsCOM.Company company = (SAPbobsCOM.Company)parameters[0];
SAPbouiCOM.Application application = (SAPbouiCOM.Application)parameters[1];
SAPbouiCOM.Form form = (SAPbouiCOM.Form)parameters[2];
SBO.UI.B1Form eventForm = (SBO.UI.B1Form)parameters[3];
UniversalFunctions.Model.CommonEventObject eventData = (UniversalFunctions.Model.CommonEventObject)parameters[4];
SBO.AddonLogic.AddonData addonData = (SBO.AddonLogic.AddonData)parameters[5];
var Client = new AvaTaxClient("Whatever I want to call the client", "1.0", Environment.MachineName, AvaTaxEnvironment.Production)
.WithSecurity("MyUsername", "MyPassword");
// Verify that we can ping successfully
var pingResult = Client.Ping();
if ((bool)pingResult.authenticated)
{
application.StatusBar.SetText("Ping success", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
try
{
// Create a simple transaction for $100 using the fluent transaction builder
var transaction = new TransactionBuilder(Client, "DEFAULT", DocumentType.SalesInvoice, "9999")
.WithAddress(TransactionAddressType.SingleLocation, "255 S King St", null, null, "Seattle", "WA", "98104", "US")
.WithLineItem(100.0m, 1, "P0000000")
.Create();
}
catch(Exception ex)
{
if (ex is Avalara.AvaTax.RestClient.AvaTaxError avaTaxError)
{
// Print the error status code (e.g. "BadRequest", "Unauthorized", etc.)
application.StatusBar.SetText("AvaTax Error Type: " + avaTaxError.statusCode, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
// Print the error message returned by AvaTax
application.StatusBar.SetText("AvaTax Error Message: " + avaTaxError.error.error.message.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
// Print the error details for each error encountered
application.StatusBar.SetText("AvaTax Error Details:", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
foreach (var detail in avaTaxError.error.error.details)
{
// Print the description and help link for each error
application.StatusBar.SetText(" Description: " + detail.description, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
application.StatusBar.SetText(" Help Link: " + detail.helpLink, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
}
// Print the full error response received from AvaTax
application.StatusBar.SetText("Full Error Response: " + avaTaxError.error.error.ToString(), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
}
}
}
else
{
application.StatusBar.SetText("Ping fail", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
}
}
}
}
I’ve tried taking the avaTaxError assignment out of the if() comparison and creating a variable inside that block instead – that gets me down to a single expected semicolon. But I still can’t understand where it wants me to put it.
if (ex is Avalara.AvaTax.RestClient.AvaTaxError)
{
var (Avalara.AvaTax.RestClient.AvaTaxError) avaTaxError;
>Solution :
Regardless of the language version, the following code should be more idiomatic, and underline that you actually intend to swallow all other exceptions:
try {
// code here
} catch (Avalara.AvaTax.RestClient.AvaTaxError avaTaxError) {
// your if body here
}
catch (Exception) {}