We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

External images unreachable

Aspose,


I am trying to open a HTML document that has images that are external to the machine. The external images are not reachable because the network is setup so that it cannot connect to the internet and will not respond to those requests. When I try to instantiate a new Document, Aspose is trying to connect to the internet to download the image. It looks like the connection gets timed out after 100 seconds. When this happens the program terminates even though I have tried to catch the exception.





Thanks you


LRS Development

Hi there,


Thanks for your inquiry. A class implementing IResourceLoadingCallback interface can be used to control how resources such as images or CSS are handled when they need to be downloaded from an external source i.e. a network or internet. Please see the following example which bans all network resources from loading.

You may use LoadOptions.WebRequestTimeout property. This property allows use to set the number of milliseconds to wait before the web request times out. The default value is 100000 milliseconds (100 seconds).

If your program still terminating, please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. Please also share your input document. We will investigate the issue on our side and provide you more information.



Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();

loadOptions.LoadFormat = LoadFormat.Docx;<o:p></o:p>

loadOptions.ResourceLoadingCallback = new HandleResourceLoading();<o:p></o:p>

Document doc = new Document(@“C:\Temp\in.docx”, loadOptions);<o:p></o:p>

doc.Save(@“C:\Temp\out.docx”);<o:p></o:p>


public class HandleResourceLoading : IResourceLoadingCallback<o:p></o:p>

{<o:p></o:p>

public ResourceLoadingAction ResourceLoading(ResourceLoadingArgs args)<o:p></o:p>

{<o:p></o:p>

return ResourceLoadingAction.Skip;<o:p></o:p>

}<o:p></o:p>

}<o:p></o:p>



Aspose,

Setting the IResourceLoadingCallback is a helpful in the case where we know there is no external connection. Generally we do not know our users environment. In some users environments the server will not respond to the HTTP request to get the image. Once the request has timed out Aspose will crash with an Unhandled Exception.



Unhandled Exception:

System.ObjectDisposedException: Safe handle has been closed

at System.StubHelpers.StubHelpers.SafeHandleC2NHelper(Object pThis, IntPtr pCleanupWorkList)

at Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle)

at System.Threading.EventWaitHandle.Set()

at System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(IMessage msg)

at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object o)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)

at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)

Unhandled Exception:





I was able to reproduce this scenario by using a proxy application “Fiddler”. Fiddler has the ability to intercept HTTP traffic and choose what to do with the request / response. I used it to hold the request and do nothing with it. After the 100 seconds had elapsed the crash occured. Using your suggestion of the WebRequestTimeout, I was able to reproduce the same result without any external applications intercepting the request. By setting the WebRequestTimeout to 1.





static void Main(string[] args)

{

SetLicense();



Document doc;

LoadOptions loadOptions = new LoadOptions(LoadFormat.Html,null,null);



loadOptions.WebRequestTimeout = 1;

doc = new Document(“C:\external.html”,loadOptions);

}





Here is a simple HTML file that I used.







If there is anything else I need to provide, let me know.
Thank you
LRS Development
Hi there,

Thanks for your inquiry.

We have tested the scenario using latest version of Aspose.Words for .NET 16.2.0 with shared code example and have not faced any exception. Please use Aspose.Words for .NET 16.2.0 and let us know how it goes on your side. Hope this helps you. You may use ResourceLoadingArgs.Uri property to check URI of the resource and skip the resource if necessary.

Thanks you for your response. We were running Words 15.4. I saw that this issue had been fixed in 15.9 and this indeed fixes our issue.