Open.NAT
Open.NAT copied to clipboard
The CancellationTokenSource conflict in Framework 4.0
I created a Framework 4.0 WinForm application, and add OpenNAT by Nuget. And add sample code in Form Load events:
var discoverer = new NatDiscoverer();
var cts = new CancellationTokenSource(10000);
var device = await discoverer.DiscoverDeviceAsync(PortMapper.Upnp, cts);
await device.CreatePortMapAsync(new Mapping(Protocol.Tcp, 1600, 1700, "The mapping name"));
The VS report the following error during compilation.
The type or namespace name 'CancellationTokenSource' could not be found (are you missing a using directive or an assembly reference?)
If I add the reference to System.Threading, it will report another issue:
The type 'CancellationTokenSource' exists in both 'System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Hello,
This issue has nothing to do with Open.NAT.
However, for those reading this, the fix is to put the following in your usings:
using CancellationTokenSource = System.Threading.CancellationTokenSource;