I tried to implement port forwarding, but stopped at this step and cannot understand what the problem is.

UPnPNATClass upnpnat = new UPnPNATClass(); IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection; // Выбрасывает null 

    1 answer 1

    Check that the router has UPNP enabled and that you have the necessary permissions. Most likely the problem is this.

    It is also said that if you are using .NET 4.0 and higher, adding this section to app.config may help:

     <startup uselegacyv2runtimeactivationpolicy="true"> 

    Well, if nothing helps, you can try Open.NAT .

    • There are no UPNP settings on the router at all. I tried Open.NAT, here is the result -> yadi.sk/i/x9bGR1xUpf4Jk I went to the site that was offered there, checked and the error does not see me. I tried, just in case, all ports from 1600 - 1603 and from 1700 to 1703 - testermatrix
    • @testermatrix so maybe your router does not support UPNP / port forwarding at all? - andreycha
    • How can this be accurately determined? And maybe there are some other options to establish a connection for messaging on the Internet between two computers with known external dynamic addresses in c #? - testermatrix
    • @testermatrix alas, I do not know. - andreycha