The following code takes over 20 seconds to execute. I would expect it to finish in a few milliseconds. It works as expected if the src is a http uri, also some file uris finish in a reasonable time, but somehow this particular uri causes a massive slowdown. Sample file also attached as zip. This is running Aspose.Html 24.7.0
HTMLDocument doc = new HTMLDocument(“<img src="//someurl.com/a/b/icons/mail/ab2/1x/random.png"/>”, “.”);
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): HTMLNET-5697
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
The problem is caused by too long default network timeout (100 s), in case of a wrong link the network operation may be too long before it fails.
Aspose.HTML for .NET provides an opportunity to customize the network timeout value, as it is shown in the code snippet below. So it can be set shorter from your side, if it’s needed. Also see for details: Network Timeouts – How to Set in C# examples
Also there was a bug that caused that a user-defined timeout was set but had no effect on some network operations, such as image loading. We have found out and fixed it.
using System.IO;
using System.Net;
using System.Diagnostics;
using Aspose.Html.Services;
using Aspose.Html.Net;
using System;
namespace MyNamespace
{
public class HTMLNET_5697_Test
{
public static void Main()
{
var content = @"<img src=""//someurl.com/a/b/icons/mail/ab2/1x/random.png""/>";
var configuration = new Configuration();
// Call the INetworkService which contains the functionality for managing network operations
var network = configuration.GetService<INetworkService>();
// Add the TimeoutMessageHandler to the top of existing message handler chain
network.MessageHandlers.Insert(0, new TimeoutMessageHandler());
Stopwatch sw = Stopwatch.StartNew();
using (HTMLDocument doc = new HTMLDocument(content, ".", Configuration))
{
sw.Stop();
Console.WriteLine(string.Format("Elapsed time ms: {0}", sw.ElapsedMilliseconds));
}
}
// Define the TimeoutMessageHandler class that is derived from the MessageHandler class
class TimeoutMessageHandler : MessageHandler
{
public override void Invoke(INetworkOperationContext context)
{
context.Request.Timeout = TimeSpan.FromSeconds(1);
Next(context);
}
}
}
}
The issues you have found earlier (filed as HTMLNET-5697) have been fixed in this update. This message was posted using Bugs notification tool by avpavlysh