Unfortunately I have not been able to find exactly where exception is happening yet, as the code is Jitted in callbacks/new thread start when returning from polling start and crashing before logging, but there is no
GetEnumerator
direct call found anywhere in my searches, but indirectly via
List
and
Dictionary
objects when using
foreach
calls where information is stored about which files have been downloaded (yet to be deleted), which are pending (not downloaded yet), which already downloaded and deleted (duplicate check).
It is more related to these indirect
IEnumerable
operations where
GetEnumerator
is needed:
I tried to reproduce the issue a lot, but not possible. So I decided to recompile existing code where it fails and when decompiling the old code which is compiled against older version of WinSCP where
GetEnumerator
existed, it is then optimised and changed to use this instead, so .NET seems to prefer this during compilation (compiler usually try to use the fastest, best performant)
WinSCP.RemoteDirectoryInfo info1;
info1 = connection1.ListDirectory(FolderPath);
System.Collections.IEnumerator enumerator1 = info1.get_Files().GetEnumerator();
while (enumerator1.MoveNext())
{
WinSCP.RemoteFileInfo fileInfo1 = (WinSCP.RemoteFileInfo)enumerator1.Current;
Source:
RemoteDirectoryInfo fileList;
fileList = connection.ListDirectory(FolderPath);
foreach (RemoteFileInfo info in fileList.Files)
So best to keep this as all previously compiled code may use
GetEnumerator
. Many have old code which is hard to recompile so best to keep APIs compatible for quick simple update via AssemblyRedirect. Some may also use this directly if it is more optimised and was available.
Sample AssemblyRedirect used in .NET applications:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WinSCPnet" publicKeyToken="2271ec4a3c56d0bf" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-1.65535.65535.65535" newVersion="1.15.0.14793"/> <!-- 6.3: 1.15.0.14793 6.1.2 = 1.14.0.13797 (winscpnet.dll version) -->
</dependentAssembly>
</assemblyBinding>
</runtime>