cancel
Showing results for 
Search instead for 
Did you mean: 

iText7 - Cannot load license file

SachaHutton
Level 2
I've a trial license for iText7 and need to load the license file using this code:

string path = @"<path to JSON file>";
System.IO.FileInfo file = new System.IO.FileInfo(path);
LicenseKey.LoadLicenseFile(file);​


I can successfully do this in Visual Studio but when I try to run it in Blue Prism, I get the following error:

Internal : Could not execute code stage because exception thrown by code stage: The type initializer for 'iText.Licensing.Base.LicenseKey' threw an exception.

I'm using the correct licensing base DLL (I've confirmed this as I'm using the same one within Visual Studio) and in the XML, LoadLicenseFile can take either type - System.IO.FileInfo or System.IO.Stream.

Has anyone ever come across this before and if so, what was their workaround?
3 REPLIES 3

ewilson
Staff
Staff
@SachaHutton,

According to the NuGet page for iText7 there are quite a few dependencies​. Do you have all of the necessary dependency libraries installed too? Keep in mind they will need to be deployed in the BP Automate folder most likely.

Cheers,
Eric

jdx0751
Level 4
I've run into similar issues while trying to implement iText with Blue Prism. I have found that we cannot run iText version 7.2 or newer with Blue Prism 7.0 because the DLLs required for iText 7.2 conflict with the DLLs needed to run Blue Prism 7.0. Specifically, the Newtonsoft.json.dll installed with BP is v12, but iText needs v13 at a minimum. If you put the v13 DLL in your Blue Prism install folder, Blue Prism itself will not load.

So I'd say the reason you get that error is because not all dependencies are installed on your machine. But you also will not be able to get the iText software working because of the DLL conflict with Blue Prism's base requirements. If you do get iText 7.2+ working though, let me know. I'd love to be able to use it. My current idea for a workaround is to use one of the 7.1 versions of iText, which has different dependencies that do NOT include the Newtonsoft.json.dll v13.

ewilson
Staff
Staff
The issue of conflicting file versions came up in a discussion the other day. From what I can see there's only one way to work around this. That involves creating a new AppDomain instance to load the iText DLL and it's associated dependencies into. This would require some coding.

In a nutshell, you would need to create a VBO that would handle:
  • Creating a new AppDomain instance
  • Load iText (it's dependencies should be handled automatically)
  • Expose actions that could be used to call into the custom AppDomain to work with the methods exposed by iText.
I came across this following article that discusses the general idea and offers a C# example.

https://jonathancrozier.com/blog/how-to-dynamically-load-different-versions-of-an-assembly-in-the-same-dot-net-application#:~:text=As%20stated%20in%20the%20previous,help%20us%3B%20meet%20Application%2...

At some point in the next week or two, when I have some time, I'm going to try creating a specific example of this in Blue Prism.

Cheers,
Eric