I am writing a code to upload a file to an sftp server via WinSCP. Everything else in my code works except when i started to include WinSCP into the code. The Assembly setup fails as it shows error where Object Reference not set to an instance of an object.
This is running on Windows Services using VS 2010 included with WinSCP .net references.
Below is the code that sets up the assembly , i am not able to use NuGet as that requires higher version of Visual Studio.
So i have to create this assembly which i got from WinSCP web itself however i do not understand what i am missing here.
try
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string resName = executingAssembly.GetName().Name + "." + "WinSCP.exe";
using (Stream resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(resName))
using (Stream file = new FileStream(executablePath, FileMode.Create, FileAccess.Write))
{
resource.CopyTo(file);
}
}
catch (System.Exception ex)
{
WriteToFile("Cant setup assembly : " + ex.Message);
Result should be that when the assembly successfully created , then the upload sessions will be able to go through as at the moment the upload sessions i am receiving an error "The version of C:\Windows\TEMP\WinSCP.tmp311D.exe () does not match version of this assembly somedir\WinSCPnet.DLL (5.15.2.0)."
A small assistance will be very helpful.
I found the problem. Apparently, I already have the assembly, that is why the error mentioned that I have the wrong assembly version. But, the main reason it couldn't match is because
My problem has been solved.