LeBlues
LeBlues

Reputation: 301

Tamir.SharpSsh Could not load file or assembly 'DiffieHellman

private void OVConnection()
{
    try {
        //Create a new JSch instance
        JSch jsch = new JSch();

        this.Dispatcher.BeginInvoke(new Action<Status>(DisplayStatus), Status.Connecting);
        //Create a new SSH session
        string host = "url"; //url
        string user = "***"; //ssh username
        string pass = "*******"; //ssh password
        int sshPort = 22; //ssh port
        int rPort = 3306;
        int lPort = 3306;

        int port = Convert.ToInt32(sshPort);

        session = jsch.getSession(user, host, port);
        session.setHost(host);
        session.setPassword(pass);

        UserInfo ui = new MyUserInfo();
        session.setUserInfo(ui);

        session.connect();

        //Set port forwarding on the opened session
        session.setPortForwardingL(lPort, "localhost", rPort);

        if (session.isConnected()) {
            MyDatabase();
        }
    }
    catch (Exception ex) {
        MessageBox.Show(ex.Message);
        this.Dispatcher.BeginInvoke(new Action<Status>(DisplayStatus), Status.NotConnected);
    }
}

I get:

Session.connect: System.IO.FileNotFoundException: Could not load file or assembly 'DiffieHellman, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

File name: 'DiffieHellman, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
   at Tamir.SharpSsh.jsch.jce.DH.getE()
   at Tamir.SharpSsh.jsch.DHG1.init(Session session, Byte[] V_S, Byte[] V_C, Byte[] I_S, Byte[] I_C)
   at Tamir.SharpSsh.jsch.Session.receive_kexinit(Buffer buf)
   at Tamir.SharpSsh.jsch.Session.connect(Int32 connectTimeout)

=== Pre-bind state information ===

LOG: DisplayName = DiffieHellman, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Development/2013/OV Projects/OmniView Documents Upload/Documents Upload/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Tamir.SharpSSH, Version=1.1.1.13, Culture=neutral, PublicKeyToken=null.

===

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Development\2013\OV Projects\OmniView Documents Upload\Documents Upload\bin\Debug\Documents Upload.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Development/2013/OV Projects/OmniView Documents Upload/Documents Upload/bin/Debug/DiffieHellman.DLL.
LOG: Attempting download of new URL file:///C:/Development/2013/OV Projects/OmniView Documents Upload/Documents Upload/bin/Debug/DiffieHellman/DiffieHellman.DLL.
LOG: Attempting download of new URL file:///C:/Development/2013/OV Projects/OmniView Documents Upload/Documents Upload/bin/Debug/DiffieHellman.EXE.
LOG: Attempting download of new URL file:///C:/Development/2013/OV Projects/OmniView Documents Upload/Documents Upload/bin/Debug/DiffieHellman/DiffieHellman.EXE.

I can not figure out why.

Upvotes: 5

Views: 10133

Answers (3)

Jay
Jay

Reputation: 101

private static void CopyfileToSFTP(string filePath)
        {
            try
            {
                
                log.Info("Started Copying file to sftp Server...");
                Tamir.SharpSsh.Sftp sftp = new Tamir.SharpSsh.Sftp(ConfigurationManager.AppSettings.Get("SFTPHost"), ConfigurationManager.AppSettings.Get("SFTPUserName"), ConfigurationManager.AppSettings.Get("SFTPPassword"));
                log.Info("sftp Server connecting");
                sftp.Connect(Convert.ToInt32(ConfigurationManager.AppSettings.Get("SFTPPort")));

                log.Info("sftp Server connected");
                sftp.Put(filePath, ConfigurationManager.AppSettings["SFTPFileLocationPath"]);
                log.Info("sftp Server file pushed to location");
                sftp.Close();

            }
            catch (Exception e)
            {
                log.Info("Error : " + e.Message);
            }

            log.Info("SFTP server file writing Done..");

        }

I had the same error in production on this line sftp.Put(filePath, ConfigurationManager.AppSettings["SFTPFileLocationPath"]);

By just copying DiffieHellman.dll and Org.Mentalis.Security.dll to deployed folder solved the issue.

Upvotes: 0

Mukesh Kumar Mehta
Mukesh Kumar Mehta

Reputation: 61

I got same error but when i add dll DiffieHellman.dll and Org.Mentalis.Security.dll then it is working.

Upvotes: 5

dunc
dunc

Reputation: 91

I had the same error and was able to resolve it by adding this NuGet package from Mentalis to my project references.

Make sure you have the NuGet package manager installed, first. After installing it, I did this:

Right-click References > Manage nuget packages > search for DiffieHellman > Install

This worked for me.

Upvotes: 7

Related Questions