5
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);
    }
}

我得到:

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.

我不知道为什么。

4

2 回答 2

6

我遇到了同样的错误,并且能够通过将 Mentalis 中的这个 NuGet 包添加到项目引用中来解决它。

确保首先安装了NuGet 包管理器。安装后,我这样做了:

右键单击 References > Manage nuget packages > 搜索 DiffieHellman > Install

这对我有用。

于 2014-11-24T19:26:26.157 回答
4

我遇到了同样的错误,但是当我添加 dll DiffieHellman.dll 和 Org.Mentalis.Security.dll 时,它就可以工作了。

于 2017-01-24T12:07:19.943 回答