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=18.104.22.16801, 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:
- 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 22.214.171.12405
- 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="126.96.36.19901" newVersion="188.8.131.5205" /> </dependentAssembly> </assemblyBinding> </runtime>
This binding redirect ensures that a version of the WinSCP code runs that has the RemotePath type when the version 184.108.40.20601 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.