QuickBooks-V3-DotNET-SDK
QuickBooks-V3-DotNET-SDK copied to clipboard
Serilog Method not found blocking issue
Using the latest IPP version (14.6.3), whenever attempting to pass the ServiceContext as an argument, the following error message is returned;
"Method not found: 'Serilog.LoggerConfiguration Serilog.FileLoggerConfigurationExtensions.File(Serilog.Configuration.LoggerSinkConfiguration, System.String, Serilog.Events.LogEventLevel, System.String, System.IFormatProvider, System.Nullable1<Int64>, Serilog.Core.LoggingLevelSwitch, Boolean, Boolean, System.Nullable1<System.TimeSpan>, Serilog.RollingInterval, Boolean, System.Nullable1<Int32>, System.Text.Encoding, Serilog.Sinks.File.FileLifecycleHooks)'."
I've seen multiple answers relating to the ServiceContext saying to downgrade Serilog.Sinks.Debug to an outdated version but my project does not use Serilog. I'll attach the entire function that is failing.
OAuth2RequestValidator ouathValidator = new OAuth2RequestValidator(
"ACCESS_TOKEN");
ServiceContext serviceContext = new ServiceContext(
"AUTH_CODE",
IntuitServicesType.QBO, ouathValidator);
Invoice invoice = new();
invoice.Deposit = new Decimal(0.00);
invoice.DepositSpecified = true;
List<Line> lineList = new List<Line>();
Line line = new Line();
line.Description = "Description";
line.Amount = new Decimal(100.00);
line.AmountSpecified = true;
lineList.Add(line);
invoice.Line = lineList.ToArray();
SalesItemLineDetail salesItemLineDeatil = new SalesItemLineDetail();
salesItemLineDeatil.Qty = new Decimal(1.0);
line.AnyIntuitObject = salesItemLineDeatil;
line.DetailType = LineDetailTypeEnum.SalesItemLineDetail;
line.DetailTypeSpecified = true;
invoice.DueDate = DateTime.UtcNow.Date;
invoice.DueDateSpecified = true;
invoice.TotalAmt = new Decimal(10.00);
invoice.TotalAmtSpecified = true;
invoice.EmailStatus = EmailStatusEnum.NotSet;
invoice.EmailStatusSpecified = true;
invoice.Balance = new Decimal(10.00);
invoice.BalanceSpecified = true;
invoice.TxnDate = DateTime.UtcNow.Date;
invoice.TxnDateSpecified = true;
invoice.TxnTaxDetail = new TxnTaxDetail()
{
TotalTax = Convert.ToDecimal(10),
TotalTaxSpecified = true
};
QueryService<Item> querySvcItem = new QueryService<Item>(serviceContext);
Item item = querySvcItem.ExecuteIdsQuery(
"SELECT * FROM Item WHERE Name = 'Lighting'").FirstOrDefault();
salesItemLineDeatil.ItemRef = new ReferenceType
{
Value = item.Id
};
QueryService<Customer> querySvc = new QueryService<Customer>(serviceContext);
Customer customer = querySvc.ExecuteIdsQuery
("SELECT * FROM Customer WHERE CompanyName like 'Clement%'").
FirstOrDefault();
invoice.CustomerRef = new ReferenceType()
{
Value = customer.Id
};
DataService service = new DataService(serviceContext);
Invoice addedInvoice = service.Add<Invoice>(invoice);
Having tried multiple times to debug and re-arrange code to get to the bottom of the issue, it appears anytime the serviceContext is passed in as an argument to either the QueryService
or DataService
Additional note that none of this code is my own, this is all taken from an example found in the docs so I'm confident in ruling out anything on my end and that the issue is in the IppDotNetSdkForQuickBooksApiV3 itself.
Will take a look and get back to you! If you can get the fiddler logs that would be helpful
Is there any update on this you can provide @nimisha84?
Next 2 weeks is our SDK sprint and I will spend time on this and get back to you.
Did u already try deleting bin/debug folders and cleanup ->verify sdk installed version from nuget for each of your sub projects-> make sure they are al same->build.
It seems some old code is being referenced due to dll hell.
Other things to try- follow the suggestion to downgrade if that is what helped other devs.
Also, this seems incorrect ServiceContext serviceContext = new ServiceContext( "AUTH_CODE", IntuitServicesType.QBO, ouathValidator);
First param is the realm id or company id that you get back from oauth call. It should not be the auth_code.
I have the same issue unfortunately. I tried your suggested steps of cleanup and removing the bin/debug folders: no difference.
Edit: removed all Serilog packages and QuickBooksV3 then reinstalled QuickBooksV3 and everything works fine. So it seems to me this package does not play well with newer versions of Serilog.
While running into this again (web.config assembly binding was still pointing to the updated version) i noticed PR #221. Please look into this so this issue is also resolved. Having a SDK with a dependency on a logging framework is... not optimal to put it lightly.
Thanks!
Seeing the same exact issue due to the fact that we use a newer version of Serilog. It would be great if #221 landed as it would resolve this issue.
[2022-08-09 18:33:40 ERR] An unhandled exception has occurred while executing the request.
System.Exception: Unhandled Exception
---> System.MissingMethodException: Method not found: 'Serilog.LoggerConfiguration Serilog.ConsoleLoggerConfigurationExtensions.Console(Serilog.Configuration.LoggerSinkConfiguration, Serilog.Events.LogEventLevel, System.String, System.IFormatProvider, Serilog.Core.LoggingLevelSwitch, System.Nullable`1<Serilog.Events.LogEventLevel>, Serilog.Sinks.SystemConsole.Themes.ConsoleTheme)'.
I used this workaround in .net core to keep my Serilog sinks on latest version
Created a new Interface IQuickbooksLogger
public interface IQuickbooksLogger: Serilog.ILogger { }
Implement it and inject the Microsoft.Extensions.Logging.ILogger<T>
public class QuickbooksLogger : IQuickbooksLogger
{
private readonly ILogger<QuickbooksLogger> _logger;
public QuickbooksLogger(ILogger<QuickbooksLogger> logger)
{
_logger = logger;
}
public void Write(LogEvent logEvent)
{
_logger.Log(logEvent.Level switch
{
LogEventLevel.Verbose => LogLevel.Trace,
LogEventLevel.Debug => LogLevel.Debug,
LogEventLevel.Information => LogLevel.Information,
LogEventLevel.Warning => LogLevel.Warning,
LogEventLevel.Error => LogLevel.Error,
LogEventLevel.Fatal => LogLevel.Critical,
_ => LogLevel.None
}, logEvent.RenderMessage());
}
}
Register the dependency
builder.Services.AddScoped<IQuickbooksLogger, QuickbooksLogger>();
And right after constructing OAuth2Client register as CustomLoger
_auth2Client.CustomLogger = _quickbooksLogger;
I agree with the above: this library SHOULD NOT have a dependency on a logging library like this. It is causing me issues as well that I am trying to work through. The amount of references that this project has is wrong. Please cleanup this project.
Depending on your needs, you might want to consider using the community .NET SDK QuickBooksSharp. It has a much lighter footprint and a more modern API up to date with latest .NET practices. Disclaimer: I wrote this library.
This is really bad. I have a customer who is a long time QB customer and requires integration with our dotnet application. And we keep hitting these logger issues, because we already use (actually-up-to-date) serilog. There are at least two places I've found you have to override like @Ahmad-anility's suggestion. The second one can be found if you look carefully at the Readme in the logging section. But nowhere does it explain why there is a required dependency on an out of date package, or even any package. Microsoft's extensions logger would have worked fine, or better yet, throw exceptions like a library should and let us catch them, and if other status is necessary, pass it in the return values and we can decide whether to log it.
Yeah i hate to say it, but taking a dependency on serilog is like JR Developer mode.. its really bad. Im actually embarrassed for you guys! Quickbooks should NOT have a dependency on a logging API. I know this is harsh, but this isnt a small mistake, this is a huge mistake so it needs to be called out and honestly someone should be written up and or reprimanded in your org for doing this. I Would never let something like this pass my QA