'System.NullReferenceException' occurred in WeOn (General questions)
When I execute the following code from a console application, it works fine (connects to server, transfers, etc.)
When I execute it on a background thread from a Windows Form I get the subject exception on the line:
new WeOnlyDo.Client.SFTP
I verified that the license key string is retrieved from the (encrypted) config file.
Here is a snippet:
Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConnectionStringsSection connSection = appConfig.ConnectionStrings;
uploadServer.sftpClient = new WeOnlyDo.Client.SFTP();
// for use of WeOnlyDo DLL
uploadServer.sftpClient.LicenseKey = connSection.ConnectionStrings[ LicenseKey ].ConnectionString;
uploadServer.sftpClient.Hostname = connSection.ConnectionStrings[ ISSServer ].ConnectionString;
uploadServer.sftpClient.Login = connSection.ConnectionStrings[ TestUser ].ConnectionString;
uploadServer.sftpClient.Password = connSection.ConnectionStrings[ TestPassword ].ConnectionString;
uploadServer.sftpClient.Blocking = true; // not asynchronous
uploadServer.sftpClient.Timeout = 60; // autodisconnect on inactivity in seconds, 0 means no timeout.
uploadServer.Connect(remotePath, uploadWorker);
Re: 'System.NullReferenceException' occurred
Hi Charles,
What happened when you use direct value instead reading it from config file?
I think Connect Method is missing in your code:
[code]uploadServer.sftpClient.Connect()[/code]
Drazen
Re: 'System.NullReferenceException' occurred
I got the same error when hardcoding the string values.
I am not showing the actual values.
By the way, this same code works when called from a background thread of NUnit. It fails when called from a Windows Form.
uploadServer.sftpClient = new WeOnlyDo.Client.SFTP();
uploadServer.sftpClient.LicenseKey = --- ;
uploadServer.sftpClient.Hostname = 149.59.1.72 ;
uploadServer.sftpClient.Login = --- ;
uploadServer.sftpClient.Password = --- ;
uploadServer.sftpClient.Blocking = true;
uploadServer.sftpClient.Timeout = 60;
uploadServer.sftpClient.RemotePath = remotePath; // has to be set again repeatedly in Upload
uploadServer.sftpClient.Connect();
Re: 'System.NullReferenceException'
Charles,
which line in your code produce such error? Did you perhaps try our C# samples? They are made for Windows Form. Do you have problem with them?
You can find it in component Samples folder.
Drazen
Re: 'System.NullReferenceException' occurred
I'm confident that the sample code works just fine.
My problem is probably caused by something else--not the use of a Windows Form.
Do you happen to know what object the SFTP constructor dereferences that would cause such an exception?
This assumes that the debugger and message are right about the constructor throwing the null reference exception.
Re: 'System.NullReferenceException'
Charles,
Can you maybe zip and send us your example to techsupport@weonlydo.com ? I order to deal with your problem we will need to duplicate it somehow.
Drazen
Re: 'System.NullReferenceException' occurred
Thank you for your help!
It turned out that I had suscribed to thread and .NET exceptions which caused the debugger to give the impression that the null reference was coming from the constructor when in fact the exception happened later in the code. Removing the exception subscriptions allowed me to see where the exception was really coming from.