Trying to use an external library in my Android project, but managed code stripping causes an error.

Hi, I’m trying to use the SSH.Net library in my Android project, however I’m running into an error. Specifially, MissingMethodException: Default constructor not found for type Renci.SshNet.Security.KeyExchangeDiffieHellmanGroupExchangeSha256.

I’ve determined the problem is to do with ‘Managed Code Stripping’ in project settings, because if I switch to Mono and disable the option, the library works fine. I’ve read about link.xml files to disable stripping for particular code, however the contents I have at the minute do not help and the error persists:

<linker>
    <assembly fullname="Renci.*" preserve="all">
        <namespace fullname="Renci.SshNet" preserve="all"/>
        <namespace fullname="Renci.SshNet.*" preserve="all"/>
        <type fullname="Renci.SshNet" preserve="all"/>
        <type fullname="Renci.SshNet.*" preserve="all"/>
    </assembly>
    <assembly fullname="Renci.SshNet.*" preserve="all"/>

    <assembly fullname="Renci.SshNet.Sftp" preserve="all"/>
    <assembly fullname="Renci.SshNet.Messages" preserve="all"/>
    <assembly fullname="Renci.SshNet.Compression" preserve="all"/>

    <assembly fullname="Renci.SshNet.Security.*" preserve="all">
        <namespace fullname="Renci.SshNet.Security" preserve="all"/>
        <namespace fullname="Renci.SshNet.Security.*" preserve="all"/>
        <type fullname="Renci.SshNet.Security" preserve="all"/>
        <type fullname="Renci.SshNet.Security.*" preserve="all"/>
        <type fullname="Renci.SshNet.Security.KeyExchangeDiffieHellmanGroupExchangeSha256" preserve="all"/>
    </assembly>
</linker>

(you may be able to tell I just wrote as many random lines as I could hoping it would fix the problem)

So my question is, what would a link.xml file need to contain to stop the SSH.Net library code from being stripped? And unfortunately, I cannot use Mono as it does not offer arm64 builds.

Edit: I’ve also found out by googling the error code (-2146233069), that the class is accessed dynamically so I believe this requires the link.xml file to change (reading the documenttion.)

Thanks.

Try to use the assembly element with the preserve=“all” attribute for each managed assembly by full name without wildcards. That should prevent any of the assemblies listed from being stripped, as if managed code stripping is disabled for this assemblies. There is no need to preserve specific name spaces or types within those assemblies then.

Found solution -, thanks to @JoshPeterson

link.xml works fine, but without astercs

<?xml version="1.0" encoding="UTF-8"?>
<linker>
    <assembly fullname="Renci" preserve="all">
        <namespace fullname="Renci.SshNet" preserve="all" />
        <type fullname="Renci.SshNet" preserve="all" />
    </assembly>
    <assembly fullname="Renci.SshNet" preserve="all" />
    <assembly fullname="Renci.SshNet.Sftp" preserve="all" />
    <assembly fullname="Renci.SshNet.Messages" preserve="all" />
    <assembly fullname="Renci.SshNet.Compression" preserve="all" />
    <assembly fullname="Renci.SshNet.Security" preserve="all">
        <namespace fullname="Renci.SshNet.Security" preserve="all" />
        <type fullname="Renci.SshNet.Security" preserve="all" />
        <type fullname="Renci.SshNet.Security.KeyExchangeDiffieHellmanGroupExchangeSha256" preserve="all" />
    </assembly>
</linker>

I tried the XML on MagicLeap but the errror persist. how to fix it please i would really appreciate the help.