Overcoming WinSCP Assembly Issues in BizTalk 2016

Recently I was having issues on BizTalk 2016 getting the SFTP adapter to work correctly. I had followed all of the steps listed at Michael Stephenson’s blog entry here, but I was still getting this error:

A message sent to adapter “SFTP” on send port “<send port name>” with URI “sftp://<port URI>” is suspended.
Error details: System.TypeLoadException: Could not load type “WinSCP.RemotePath” from assembly “WinSCPnet, Version=1.3.7.7601, Culture=neutral, PublicKeyToken=…”

I made sure nothing was GAC’ed and the correct version of the dll was in the BizTalk program files folder, but still I had this error.

I was able to add a reference to the dll that had this version in a project and in the object browser it showed that the RemotePath type did not exist in the dll file. I checked on Nuget for WinSCP but could not find a version that matched and had the RemotePath type in it.

Here is my solution:

  1. I downloaded the absolute latest version from the Nuget WinSCP site. When running Michael’s script it downloads an older version of the dll. I installed the absolute latest version and then copied the WinSCP.exe and WinSCPnet.dll files from the C:\Program Files (x86)\WinSCP folder to the BizTalk program files folder just like the script does. For me the files had version 1.7.2.10905
  2. Then I added an assembly binding redirect to the BizTalk config files (what I added is between the dependentAssembly tags in purple):
<runtime>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="BizTalk Assemblies;Developer Tools;Tracking;Tracking\interop" />
      <dependentAssembly>
        <assemblyIdentity name="WinSCPnet" publicKeyToken="2271ec4a3c56d0bf" culture="neutral" />
        <bindingRedirect oldVersion="1.3.7.7601" newVersion="1.7.2.10905" />
      </dependentAssembly>

    </assemblyBinding>
  </runtime>

This binding redirect ensures that a version of the WinSCP code runs that has the RemotePath type when the version 1.3.7.7601 is invoked. It appears the BizTalk SFTP adapter was bound to this version but I could not find a version that had the RemotePath type.

I updated both the BTSNTSvc.exe.config and the BTSNTSvc64.exe.config files and restarted the host instances.

Note: I noticed that the BizTalk 2016 CU 7 updated its support for WinSCP to a newer version so after applying the cumulative update the BizTalk SFTP adapter will be referencing a new version of WinSCP so you may not need this any longer after CU 7.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: