1

When I try to use puppeteersharp in AX I get a error "Method not found: 'Void Microsoft.Extensions.Logging.LoggerExtensions.LogError(Microsoft.Extensions.Logging.ILogger, System.Exception, System.String, System.Object[])'."

I have a custom DLL added to my AX project where I create a PDF but I call this method from AX. The DLL alone is working fine since I tested it outside of my AX project yet when I call it from AX the error occours. I tried different verions but there is always a problem with Microsoft.Extensions.Logging DLL.

EDIT! As I looked at code the method I seek is in Microsoft.Extensions.Logging.Abstractions. Since in AX i found that the DLL version is 1.1.2 and has no 4th method for LogError where you can add Exception value. Is there any safe way to update DLL in AX365 onprem?

 //X++ code
 class ConvertXMLtoPDF
 {
 public static void main(Args _args)
 {
 try
 {
    helper.PuppeteerPDF();
 }
 catch(Exception::CLRError)
 {
    System.Exception ex = CLRInterop::getLastException();
    info(ex.ToString());
 }
 }}

 C# code
using PuppeteerSharp;
using PuppeteerSharp.Media;
using Microsoft.Extensions.Logging;

 public async void PuppeteerPDF()
    {
        string path = @"C:\Temp\test\tes2t.pdf";
        string save = @"C:\Temp\test\test.html";
        var options = new LaunchOptions
        {
            Headless = true,
            ExecutablePath = "C:\\Program Files\\Google\\Chrome\\Application\\Chrome.exe"

        };
        try
        {
            using (var browser = await Puppeteer.LaunchAsync(options))  // <--- here the error occours
            using (var page = await browser.NewPageAsync())
            {
                await page.GoToAsync(save);
                var result = await page.GetContentAsync();
                await page.PdfAsync(path, new PdfOptions
                {
                    Format = PaperFormat.A4,
                    DisplayHeaderFooter = true,
                    Scale = (decimal)0.5,
                    PrintBackground = true,

                });
                await page.DisposeAsync();
                await browser.DisposeAsync();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            logger.LogError(ex, "test");
            logger.LogInformation(ex, "test");

        }

    }
Tweene
  • 257
  • 4
  • 16

0 Answers0