Assembly loading issue since Groupdocs.Conversion 23.6.0

Everything was working fine before version 23.6.0 of Groupdocs.Conversion.
Short explanation of my setup:
I’m building a .NET 4.8 C# Library Project which has a function to Convert any Document to a PDF.
This is the function:

        // Initialize a new instance of LoadOptions
        var loadOptions = new WordProcessingLoadOptions();

        // Initialize a new instance of WordProcessingBookmarksOptions
        var bookmarksOptions = new WordProcessingBookmarksOptions
        {
            // Set the BookmarksOutlineLevel
            HeadingsOutlineLevels = 9 // Set the level as per your requirement
        };

        // Set the WordProcessingBookmarksOptions to the LoadOptions
        loadOptions.BookmarkOptions = bookmarksOptions;

        // Convert to PDF
        using (var converter = new Converter(sourcePath, () => loadOptions))
        {
            var convertOptions = new PdfConvertOptions();
            convertOptions.PdfOptions.FormattingOptions.PageMode = PdfPageMode.UseNone;
            converter.Convert(outFileName, convertOptions);
        }

On the other side I have a PowerShell Script which is loading all the builded DLLs to call my C# function above:

function InitializePdfConversion() {
  $binFolderLocation = $assetsFolderLocation + "/bin"

  $dllsToLoad = (
    ($binFolderLocation + "/Aspose.Drawing.Common.dll"),
    # ($binFolderLocation + "/harfbuzz.dll"),
    ($binFolderLocation + "/Microsoft.Bcl.AsyncInterfaces.dll"),
    ($binFolderLocation + "/Microsoft.Extensions.Logging.Abstractions.dll"),
    ($binFolderLocation + "/System.Buffers.dll"),
    ($binFolderLocation + "/System.Collections.Immutable.dll"),
    ($binFolderLocation + "/System.Diagnostics.DiagnosticSource.dll"),
    ($binFolderLocation + "/System.Drawing.Common.dll"),
    ($binFolderLocation + "/System.Memory.dll"),
    ($binFolderLocation + "/System.Numerics.Vectors.dll"),
    ($binFolderLocation + "/System.Reflection.Metadata.dll"),
    ($binFolderLocation + "/System.Reflection.MetadataLoadContext.dll"),
    ($binFolderLocation + "/System.Runtime.CompilerServices.Unsafe.dll"),
    ($binFolderLocation + "/System.Security.AccessControl.dll"),
    ($binFolderLocation + "/System.Security.Permissions.dll"),
    ($binFolderLocation + "/System.Security.Principal.Windows.dll"),
    ($binFolderLocation + "/System.Text.Encoding.CodePages.dll"),
    ($binFolderLocation + "/System.Text.Encodings.Web.dll"),
    ($binFolderLocation + "/System.Text.Json.dll"),
    ($binFolderLocation + "/System.Threading.Tasks.Extensions.dll"),
    ($binFolderLocation + "/System.ValueTuple.dll"),
    ($binFolderLocation + "/DocumentToPdfConversion.dll"),
    ($binFolderLocation + "/GroupDocs.Conversion.dll")
  )

  foreach ($dll in $dllsToLoad) {
    LoadDll $dll
  }
  
  $global:convertToPdf = $true
  Write-Host "Initialized PDF conversion" -ForegroundColor Green
}

function LoadDll($dllLocation) {
  if ($true -eq (Test-Path -LiteralPath $dllLocation)) {
    Write-Host "`n Try to load DLL $dllLocation"

    # $fileStream = ([System.IO.FileInfo] (Get-Item (Get-ChildItem $dllLocation).FullName)).OpenRead();
    # $assemblyBytes = new-object byte[] $fileStream.Length
    # $readBytes = $fileStream.Read($assemblyBytes, 0, $fileStream.Length);
    # $fileStream.Close();
    # $loadedAssembly = [System.Reflection.Assembly]::Load($assemblyBytes);

    Add-Type -LiteralPath $dllLocation
  }
}

I tried two different ways in my “LoadDll” Function to load the DLLs.
The code which is commented out, is the initial way I was loading my DLLs before version 23.6.0. Also before this version there were only 2 DLLs which I had to load: “GroupDocs.Conversion.dll” and the “DocumentToPdfConversion.dll”, which is my projects DLL.
Because I thought that we are doing something with loading the DLLs, I tried another way of loading the DLLs. This is the code which is currently not commented out:

Add-Type -LiteralPath $dllLocation

Since version 23.6.0 there are many more dependencies but I’m having trouble loading these DLLs to call my function. I’m getting the following error with my new approach:

System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

The LoaderException property said this:

LoaderExceptions : {System.IO.FileNotFoundException: Could not load file or assembly 'System.Memory, Version=4.0.1.1,
                   Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot
                   find the file specified.
                   File name: 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

               WRN: Assembly binding logging is turned OFF.
               To enable assembly bind failure logging, set the registry value
               [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
               Note: There is some performance penalty associated with assembly bind failure logging.
               To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
               , System.IO.FileNotFoundException: Could not load file or assembly 'System.Memory, Version=4.0.1.1,
               Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot
               find the file specified.
               File name: 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

               WRN: Assembly binding logging is turned OFF.
               To enable assembly bind failure logging, set the registry value
               [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
               Note: There is some performance penalty associated with assembly bind failure logging.
               To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
               , System.IO.FileNotFoundException: Could not load file or assembly 'System.Memory, Version=4.0.1.1,
               Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot
               find the file specified.
               File name: 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

               WRN: Assembly binding logging is turned OFF.
               To enable assembly bind failure logging, set the registry value
               [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
               Note: There is some performance penalty associated with assembly bind failure logging.
               To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
               , System.IO.FileNotFoundException: Could not load file or assembly 'System.Memory, Version=4.0.1.1,
               Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot
               find the file specified.
               File name: 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

               WRN: Assembly binding logging is turned OFF.
               To enable assembly bind failure logging, set the registry value
               [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
               Note: There is some performance penalty associated with assembly bind failure logging.
               To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
               ...}

When I’m trying to load the DLLs with the initial way:

  $fileStream = ([System.IO.FileInfo] (Get-Item (Get-ChildItem $dllLocation).FullName)).OpenRead();
  $assemblyBytes = new-object byte[] $fileStream.Length
  $readBytes = $fileStream.Read($assemblyBytes, 0, $fileStream.Length);
  $fileStream.Close();
  $loadedAssembly = [System.Reflection.Assembly]::Load($assemblyBytes);

I’m getting the following exception out of this line of my C# code:
converter.Convert(outFileName, convertOptions);

The type initializer for ' ' threw an exception.

There isn’t anymore information I can get out of the exception sadly.

Any ideas what I’m doing wrong?

Thanks for the responses.

@chillmau
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CONVERSIONNET-6311

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
We’ll notify you if any further details are required.