web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Exception in D365 when Using PDF/A-3 Creation DLL

(2) ShareShare
ReportReport
Posted on by 19
Hi
I have developed a C# class library that creates a PDF/A-3 document with an XML attachment. The code functions correctly when executed as a console application, but I encounter an error when using it as a DLL in Dynamics 365 Finance and Operations.
 
Error : Method not found: 'Void Microsoft.Extensions.Logging.LoggerExtensions.LogError(Microsoft.Extensions.Logging.ILogger, System.Exception, System.String, System.Object[])'.
 
Code Snippet:
 
public static byte[] CreatePdfA3WithAttachment(byte[] pdfContent, byte[] xmlData, Stream iccProfileData)
{
    using (MemoryStream pdfStream = new MemoryStream())
    {
        PdfWriter writer = new PdfWriter(pdfStream);
        PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B,
                                                    new PdfOutputIntent("Custom ICC Profile", "", "https://www.color.org", "", iccProfileData));
        Document document = new Document(pdfDocument);
        pdfDocument.GetDocumentInfo().SetTitle("PDF/A-3 Document with XML Attachment");
        pdfDocument.GetDocumentInfo().SetAuthor("Author Name");
        pdfDocument.GetDocumentInfo().SetSubject("PDF/A-3 Document");
        pdfDocument.GetDocumentInfo().SetKeywords("PDF/A-3, XML, iText7");
        pdfDocument.SetTagged();
        pdfDocument.GetCatalog().SetLang(new PdfString("en-US"));
        pdfDocument.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true));
        using (MemoryStream existingPdfStream = new MemoryStream(pdfContent))
        {
            try
            {
                PdfReader pdfReader = new PdfReader(existingPdfStream);
                PdfDocument existingPdf = new PdfDocument(pdfReader);
                existingPdf.CopyPagesTo(1, existingPdf.GetNumberOfPages(), pdfDocument);
                existingPdf.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception while adding existing content: " + ex.Message);
            }
        }
        using (MemoryStream xmlStream = new MemoryStream(xmlData))
        {
            PdfDictionary fileParameter = new PdfDictionary();
            PdfFileSpec fileSpec = PdfFileSpec.CreateEmbeddedFileSpec(
                pdfDocument, xmlStream.ToArray(), "attached.xml", "attached.xml", PdfName.ApplicationXml, fileParameter, PdfName.Data);
            pdfDocument.AddFileAttachment("attached.xml", fileSpec);
            PdfArray afArray = new PdfArray();
            afArray.Add(fileSpec.GetPdfObject());
            pdfDocument.GetCatalog().Put(new PdfName("AF"), afArray);
        }
        document.Close();
        return pdfStream.ToArray();
    }
}
Any insights into why this exception occurs within D365 but not in a standalone application would be greatly appreciated. Additionally, advice on potential workarounds to avoid dependency conflicts with Microsoft.Extensions.Logging would be helpful.
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at
    What is the stack trace of the exception? LogError() apparently isn't used in CreatePdfA3WithAttachment() method.
     
    Which framework have you built your assembly for?
  • Suggested answer
    Anton Venter Profile Picture
    20,346 Super User 2025 Season 2 on at
    Your DLL is dependent on other DLLs and it cannot find the logging DLL. Perhaps you should copy the dependent DLLs to the PackagesLocalDIrectory/<yourmodel>/bin folder. Check the bin folder of your Visual Studio solution, all the files should be there.
  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at
    This error doesn't mean that an reference assembly wasn't found. The assembly got resolved, but the particular method (method overload) wasn't found there.
     
    It should exist (link), but it can't be found for some reason. I noticed that there are nullable reference types as parameters and I'm aware of a problem with them in X++, which was discussed in c# dll successfully added as a reference but can't be used in code. It says: Microsoft support official answer is that Nullable reference types are not yet available (no eta) in the x++ compiler and are not supported with Dynamics in the same way c# does. I'm not sure that this is the reason but it's quite possible.
  • Pratik545 Profile Picture
    19 on at
    I have added all the dependent Dll from which one of the Dll is Microsoft.Extensions.Logging.Abstraction which contains the LogError Method. But still I am not getting how this exception is being thrown.
     
    Here are the methods in the Dll.
    This application is built in .net Standard 2.0.3 and Dll I am using is iText7 along with all its dependent Dll.
     
    And also could you please suggest me how to get resolve from Nullable Reference as I am currently using the C# language version 7.3 but from the resource you have provided I can understand that Nullable Reference is supported in c# 8.0 later.
     
  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at
    You didn't mention the version. You should develop against the version of Microsoft.Extensions.Logging.Abstractions.dll included in F&O, which is what your code will use at runtime. Maybe you developed code against a version that contains the method but F&O will actually run your code with a version where the method doesn't exist.
     
    In my environment, the version of Microsoft.Extensions.Logging.Abstractions.dll is 1.1.230427. You'll find it in PackagesLocalDirectory\bin folder.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans