Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.MissingMethodException: Cannot dynamically create an instance of type 'Renci.SshNet.Security.KeyExchangeECCurve25519'. Reason: No parameterless constructor defined. #1167

Closed
Zero-Xiong opened this issue Aug 31, 2023 · 6 comments

Comments

@Zero-Xiong
Copy link

Hi guys, what's the root cause?

Version: 2020.0.2

System.MissingMethodException: Cannot dynamically create an instance of type 'Renci.SshNet.Security.KeyExchangeECCurve25519'. Reason: No parameterless constructor defined.
at Renci.SshNet.Session.WaitOnHandle(WaitHandle, TimeSpan)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.CreateAndConnectSession()

@Rob-Hague
Copy link
Collaborator

Are you trimming your application?

@emetlashevskiy
Copy link

I have some error, how resolve it?
On win64 work fine, but on linux:
System.MissingMethodException: Cannot dynamically create an instance of type 'Renci.SshNet.Security.KeyExchangeECCurve25519'. Reason: No parameterless constructor defined.
at Renci.SshNet.Session.WaitOnHandle

@emetlashevskiy
Copy link

emetlashevskiy commented Sep 1, 2023

Yes, if untrimmed app when work fine!
You need set "PublishTrimmed" to false, or remove from *.csproj.

@emetlashevskiy
Copy link

Another problem, how disable trimming my app if PublishAOT is true?
I tryed

<PackageReference Include="SSH.NET" Version="2020.0.2">
    <IsTrimmable>false</IsTrimmable>
</PackageReference>

but no effect.

@Rob-Hague
Copy link
Collaborator

I don't know a lot about trimming. I think you may try "rooting" the assembly as described at this link

https://learn.microsoft.com/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-7-0#root-assemblies

(untested)

<ItemGroup>
  <TrimmerRootAssembly Include="Renci.SshNet" />
</ItemGroup>

You could even try using "descriptors" to preserve just the specific types listed here:

KeyExchangeAlgorithms = new Dictionary<string, Type>
{
{ "curve25519-sha256", typeof(KeyExchangeECCurve25519) },
{ "[email protected]", typeof(KeyExchangeECCurve25519) },
{ "ecdh-sha2-nistp256", typeof(KeyExchangeECDH256) },
{ "ecdh-sha2-nistp384", typeof(KeyExchangeECDH384) },
{ "ecdh-sha2-nistp521", typeof(KeyExchangeECDH521) },
{ "diffie-hellman-group-exchange-sha256", typeof(KeyExchangeDiffieHellmanGroupExchangeSha256) },
{ "diffie-hellman-group-exchange-sha1", typeof(KeyExchangeDiffieHellmanGroupExchangeSha1) },
{ "diffie-hellman-group16-sha512", typeof(KeyExchangeDiffieHellmanGroup16Sha512) },
{ "diffie-hellman-group14-sha256", typeof(KeyExchangeDiffieHellmanGroup14Sha256) },
{ "diffie-hellman-group14-sha1", typeof(KeyExchangeDiffieHellmanGroup14Sha1) },
{ "diffie-hellman-group1-sha1", typeof(KeyExchangeDiffieHellmanGroup1Sha1) },
};


I can't see a way on the library side to mark it as incompatible with trimming, short of fixing the actual problem which is the use of reflection here:

public IKeyExchange CreateKeyExchange(IDictionary<string, Type> clientAlgorithms, string[] serverAlgorithms)

It would probably be fixed by changing ConnectionInfo.KeyExchangeAlgorithms to Dictionary<string, Func<IKeyExchange>> instead of Dictionary<string, Type>

@Zero-Xiong
Copy link
Author

PublishTrimmed

Thanks for comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants