I\'m trying to add new static port mapping in my c# application. Because my application runs as a server and i want its to listen on the port 8000.
NATUPNPLi
You need to set mappings to a new instance:
For example:
var mappings = new List();
Then you can call:
mappings.Add(8000, "TCP", 8000, "192.168.1.100", true, "Local Web Server");
From your edit:
upnpnat.StaticPortMappingCollection; // this is your problem.
The collection is coming back as null. Therefore you cannot add to the collection.
You may have to do:
NATUPNPLib.IStaticPortMappingCollection mappings = new StaticPortMappingCollection();
From Codesleuth's comment:
I believe the answer is that his router isn't configured as a UPnP gateway, or that he has no permissions. The StaticPortMappingCollection is null if either of those cases are true. I suggest you edit this into your answer as you've got the right reason for the error anyway. Checking for null first is the only way to deal with the error