We help IT Professionals succeed at work.

Itext issue Loading Assembly file

298 Views
Last Modified: 2020-09-17
Experts,

What would cause the following when running the this command :


Add-Type -Path 'C:\Test-CitrixRebootScript\UtilityFunctions\itext2\itextsharp.dll'

Open in new window


PS C:\Test-CitrixRebootScript\UtilityFunctions\itext2> Add-Type -Path 'C:\Test-CitrixRebootScript\UtilityFunctions\itext
2\itextsharp.dll'
Add-Type : Could not load file or assembly 'file:///C:\Test-CitrixRebootScript\UtilityFunctions\itext2\itextsharp.dll'
or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1
+ Add-Type -Path 'C:\Test-CitrixRebootScript\UtilityFunctions\itext2\it ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Type], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand

I have attempted the following already :

Downloaded the most recent version of itext
Downloaded and unblocked folder and files within..
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
Which OS? Can't reproduce on W2k12R2, W2k16, Win10.
It could be that the dll requires .NET 2.0 (can't find a list of requirements), which is not installed by default.
CERTIFIED EXPERT

Author

Commented:
Not sure why, but I had to set-location to my itext directory before It would work. I couldn't call it by full path.

Importing using this :
*Worked*
Add-Type -Path '.\itextsharp.dll'

Open in new window


*Didn't work**
Add-Type -Path 'C:\Test-CitrixRebootScript\UtilityFunctions\itext2\itextsharp.dll'

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
Can't reproduce that, either. Can load from pretty much any folder, including the HKLM drive.
Did you first try it from a file system drive or from another provider?
Can you use the full path when you're in the dll's folder?
Are there other dlls in the folder where you were during your first attempt?
CERTIFIED EXPERT

Author

Commented:
oBdA no, there are only two files in that folder, the XML and the DLL associated with iText.

PS C:\Test-CitrixRebootScript\UtilityFunctions\itext2>
Unblock-File -Path .\itextsharp.dll

Open in new window


PS C:\Test-CitrixRebootScript\UtilityFunctions\itext2>
Add-Type -Path 'C:\Test-CitrixRebootScript\UtilityFunctions\itext
2\itextsharp.dll'

Open in new window

Add-Type : Could not load file or assembly 'file:///C:\Test-CitrixRebootScript\UtilityFunctions\itext2\itextsharp.dll'
or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1
+ Add-Type -Path 'C:\Test-CitrixRebootScript\UtilityFunctions\itext2\it ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Type], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
CERTIFIED EXPERT

Author

Commented:
I agree with you however, that should not have been an issue if it worked while local to the folder... Strange..
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION