Hi Mesut I'm not familiar with this library but is suspect if you test your local variable mappings for null before the loop it will be null. Take a look at the documentation for this library to see if there is anything you need to do in order to initialise the class so that u.StaticPortMappingCollection returns a valid collection. Cheers Ian -----Original Message----- From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx] On Behalf Of Mesut Sent: 18 October 2011 00:22 To: program-l@xxxxxxxxxxxxx Subject: [program-l] C# port forwarding problem Hi all. I'm developping a peer-to-peer application. But have problems dealing with IPv4. So I must use windows port forwarding. For this, "NATUPNPLib.dll" is used. And I've added this file to references section and "NATUPNPLib" namespace to "using" section of VS document. Following lines contains my codes. But I'm encountering with a null references exception. I'd be glad to help. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Net.Sockets; using System.Net; using NATUPNPLib; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { try { UPnPNATClass u = new UPnPNATClass(); IStaticPortMappingCollection mappings = u.StaticPortMappingCollection; // just following line throws a null reference exception foreach (IStaticPortMapping map in mappings) { // also this line makes so Console.WriteLine(map.ExternalIPAddress); } // shortly, all implimentation about "u" instance throws a null reference exception } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadKey(); } } } ** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq ** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq