Could not load file or assembly SSIS Script Task

Viewed 1150

I have a DTSx with a Script Task that will replace some labels in a Word Document and then save it as PDF but it constantly shows error : "Could not load file or assembly '' or one of its dependencies. The system cannot find the file specified." I've tried using Aspose, GemBox, Syncfusion and the error is always the same. When I use them from NuGet the Task doesn't even start...but when I copy the DLLs and all the attached files to a folder in my computer it shows the error above. I use framework 4.

Can you please help?

Thanks.

1 Answers

nuget packages and SSIS script tasks don't work. Yes, it will compile for you but when you X out of the Script Editor, the nuget packages don't get serialized in with the executable and when it runs, there's no "brains" there to download the expected assemblies. SSIS expects the assemblies to be either serialized into what gets stored in the SSIS package or to be in the Global Assembly Cache (GAC).

How do I get a nuget package installed to the GAC?

Three big steps

Find GACUTIL.exe

Open Command Prompt cd "\Program Files (x86)" and then dir /s /b gacutil.exe That will tell you where the gacutil.exe program lives (if it exists on your machine - it might not).

As a reference, here's what my development machine looks like

C:\Program Files (x86)>dir /s /b gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\x64\gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64\gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64\gacutil.exe

Make note of where one of those executables lives. As there are spaces in the path, you will need to wrap the path with double quotes to run it, i.e. "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe"

Find the assembly

Find the nuget package you need and pray that it's a signed assembly. Script Task/Component development in SSIS is a weird beast. My SSIS package is in this path \users\bfellows\Documents\Solution\Project\MyPackage.dtsx

When I edit a script task though, what happens? A new instance of VS spins up and I do the things I need to do. Say I add newtonsoft to my package so I json all the things.

enter image description here

Wait, what's the gibberish? My Project Folder is pointed at C:\Users\bfellows\AppData\Local\Temp\Vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A\VstacRTUuMELWk2UL3Wn4JQCWw\ Yes, the task/component editor uses temporary path to create a new solution and project, does all its work there and when you close out the editor, all of the project solution bits get serialized back into the SSIS package. nuget stuff is not included in the serialized bits. Ooops.

So, you need the assembly but it's in a temporary path - what do you do? You edit the package, ensure your nuget package is currently downloaded and do not close the script task. Right Click on the solution name (VstaProjects) and choose Properties.

enter image description here

Find that Path and copy the resulting value out. My solution file is located at C:\Users\bfellows\AppData\Local\Temp\Vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A\VstaProjects.sln

That's great, it's one folder above the Project Folder but we won't need the VstaProject.sln part of the path.

Open a command prompt and change directory to that location.

cd C:\Users\bfellows\AppData\Local\Temp\Vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A

From here, you have a package subfolder. The command dir /s /b packages*.dll will find all the assemblies (files with a .dll extension) located under the packages folder, recursively, and provide a brief set of information - in this case, the fully qualified path.

C:\Users\bfellows\AppData\Local\Temp\vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A>dir /s /b packages\*.dll
C:\Users\bfellows\AppData\Local\Temp\vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A\packages\Newtonsoft.Json.13.0.1\lib\net20\Newtonsoft.Json.dll
C:\Users\bfellows\AppData\Local\Temp\vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A\packages\Newtonsoft.Json.13.0.1\lib\net35\Newtonsoft.Json.dll
C:\Users\bfellows\AppData\Local\Temp\vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A\packages\Newtonsoft.Json.13.0.1\lib\net40\Newtonsoft.Json.dll
C:\Users\bfellows\AppData\Local\Temp\vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
C:\Users\bfellows\AppData\Local\Temp\vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A\packages\Newtonsoft.Json.13.0.1\lib\netstandard1.0\Newtonsoft.Json.dll
C:\Users\bfellows\AppData\Local\Temp\vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A\packages\Newtonsoft.Json.13.0.1\lib\netstandard1.3\Newtonsoft.Json.dll
C:\Users\bfellows\AppData\Local\Temp\vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A\packages\Newtonsoft.Json.13.0.1\lib\netstandard2.0\Newtonsoft.Json.dll

Goodness, that's a lot of assemblies. Which one is right for me? SSIS Script Tasks/Components are built against the 4.x Framework of the .NET language. The highest net branch listed is net45 so that's what we need to know to actually install the assembly.

packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll

Install the assembly

Open a command prompt in administrator mode. This may prompt the UAC dialog to pop and you might need to use admin credentials depending on your security set up.

Installation to the GAC is straight-forward after that.

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" /if C:\path\to\my\nuget\package.dll

/if signals Install and Force a re-install even if the assembly already exists.

If I wanted to install the newtonsoft dll from above, that syntax would be

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" /if "C:\Users\bfellows\AppData\Local\Temp\vsta\SSIS_ST140\VstatIBdQdlmHEa__RFeT36Nd9A\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll"

But I got an assembly from someone else

Fear not, you can handle this

Apparently, you can sign an assembly (aka add a strong name to an existing DLL) if it wasn't already signed h/t to @kearl

  1. Open Visual Studio Command Prompt
  2. Generate a KeyFile sn -k keyPair.snk
  3. Get the MSIL for the assembly ildasm SomeAssembly.dll /out:SomeAssembly.il
  4. Rename the original assembly, just in case ren SomeAssembly.dll SomeAssembly.dll.orig
  5. Build a new assembly from the MSIL output and your KeyFile ilasm SomeAssembly.il /dll /key=keyPair.snk
Related