You need to set the mappings to a new instance:
For example:
var mappings = new List<Mapping>();
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 returns as null. Therefore, you cannot add to the collection.
You may have to:
NATUPNPLib.IStaticPortMappingCollection mappings = new StaticPortMappingCollection();
From Codesleuth comment:
I believe the answer is that its router is not configured as a UPnP gateway or that it does not have permissions. StaticPortMappingCollection is null if any of these cases are true. I suggest you edit this in your answer, since you have the correct cause of the error. Checking zero first is the only way to handle the error.
Darren davies
source share