Pregunta

Although the current Mono project's ServicePointManager class has the DnsRefreshTimeout property enabled into its interface. The related property isn't implemented.

Sample call:

ServicePointManager.DnsRefreshTimeout = 10*60*1000; // 10 minutes

When running my application I get the next exception on runtime:

The requested feature is not implemented. (System.NotImplementedException) at System.Net.ServicePointManager.set_DnsRefreshTimeout (Int32 value) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/ServicePointManager.cs:213

Here comes the actual implementation:

[MonoTODO]
public static int DnsRefreshTimeout
{
    get {
        throw GetMustImplement ();
    }
    set {
        throw GetMustImplement ();
    }
}

I think I don't have enough knowledge to implement this feature all by myself just because I am developing C# Mono applications since last month.

So, do anyone know one workaround for this? Or shall I request a feature implementation for the Mono project team?

I am developing a Xamarin cross-platform application and I really need to cache my DNS resolution at least for 10 minutes.

P.s. Feature requested at https://bugzilla.xamarin.com/show_bug.cgi?id=11424

¿Fue útil?

Solución

I don't have a fix, but I have a workaround:

var request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");

// Disable KeepAlive so we don't reuse  connections
request.KeepAlive = false;

// Clear out the cached host entry
var hostField     = typeof(ServicePoint).GetField("host", BindingFlags.NonPublic | BindingFlags.Instance);
var hostFieldLock = typeof(ServicePoint).GetField("hostE", BindingFlags.NonPublic | BindingFlags.Instance);
var hostLock      = hostFieldLock.GetValue(request.ServicePoint);
lock (hostLock)
    hostField.SetValue(request.ServicePoint, null);

This is based on the current version of ServicePoint for mono which you can view here as of March 2015.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top