PSWritePDF Asssembly Binding conflicts

I’m writing a script that uses the Powershell Module PSWritePDF, but it causes an exception when run in Powershell Universal.

Convert-PDFToText - Processing document <filepath> failed with error: Exception calling ".ctor" with "1" argument(s): "The type initializer for 'iText.Commons.Actions.EventManager' threw an exception."

Finding the inner stacktrace, it seems like the issue is that they use iText7, which in turns tries to load an assembly that is already loaded:

 ---> System.TypeInitializationException: The type initializer for 'iText.Commons.Actions.ProductEventHandler' threw an exception.
 ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (0x80131621)
File name: 'Microsoft.Extensions.Logging.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
 ---> System.IO.FileLoadException: Assembly with same name is already loaded
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
   at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
   at System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName)
   at iText.Commons.Actions.ProductEventHandler..cctor()
   --- End of inner exception stack trace ---
   at iText.Commons.Actions.EventManager..ctor()
   at iText.Commons.Actions.EventManager..cctor()
   --- End of inner exception stack trace ---
   at iText.Commons.Actions.EventManager.GetInstance()
   at iText.Kernel.Pdf.PdfDocument.Open(PdfVersion newPdfVersion)
   at iText.Kernel.Pdf.PdfDocument..ctor(PdfReader reader, DocumentProperties properties)
   at CallSite.Target(Closure , CallSite , Type , Object ) 

I remember there has been threads about different modules before, but I can’t find them again, was there a way to work around this?

Product: PowerShell Universal
Version: 3.7.9

Hi, I have this issue since I updated my packages.
Do you know how to resolve it?
My issue isnt on powershell but maybe its similar
I do use a newer version of Abstractions but I do allow the older version in app.config
In Visual Studio it works fine but in my Testsolution Ranorex it trows this exception.
This is what I added to app.config:

<dependentAssembly>
				<assemblyIdentity name="iText.Commons.Actions.EventManager" publicKeyToken="8354ae6d2174ddca" culture="neutral" />
				<bindingRedirect oldVersion="0.0.0.0-8.0.2.0" newVersion="8.0.2.0" />
			</dependentAssembly>
			<dependentAssembly>
				<assemblyIdentity name="iText.Commons.Actions.ProductEventHandler" publicKeyToken="8354ae6d2174ddca" culture="neutral" />
				<bindingRedirect oldVersion="0.0.0.0-8.0.2.0" newVersion="8.0.2.0" />
			</dependentAssembly>
			<dependentAssembly>
				<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
				<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
			</dependentAssembly>
			

and to my Ranorex csproj I added this, because it creates its own app.config on build. Now they are similar

    <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>

I have run into the same problem and done a little digging.

It appears other users are having the problem. It looks like PSWritePDF uses itext under the hood given the error its presenting.

Users of iText are saying this problem has been fixed by reverting to iText 7.2.4 which is located here Release iText Core/Community 7.2.4 · itext/itext-dotnet · GitHub .

This brings me to a C# project.

I suspect this is broken at the dependancy level.

other examples of this problem are here:

https://www.reddit.com/r/PowerShell/comments/17xlcmo/how_to_correctly_use_itextkernelpdfpdfdocumentnew/