Insert image causes IIS crash

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
djunges
Posts: 16
Joined: Tue Feb 19, 2008 4:54 pm

Insert image causes IIS crash

Post by djunges »

dear developers,

We ran into a problem since we use the uno automation with LibreOffice on us IIS enviroment.
The follow code is for insert an image into a document, when executing the LAST LINE then the IIS server w3wp.exe causes an exception 0xc0000409.
This code run fine on an desktop enviroment, but causes error on IIS enviroment.

Can anyone help me to understand and solve it ?

Code: Select all

unoidl.com.sun.star.lang.XMultiServiceFactory servfac = (unoidl.com.sun.star.lang.XMultiServiceFactory)xComponent;
Object bitmapTableObject = localContext.getServiceManager().createInstanceWithContext("com.sun.star.graphic.GraphicProvider", localContext);
unoidl.com.sun.star.graphic.XGraphicProvider xGraphicProvider = bitmapTableObject as unoidl.com.sun.star.graphic.XGraphicProvider;
// 
unoidl.com.sun.star.beans.PropertyValue[] v = new unoidl.com.sun.star.beans.PropertyValue[1];
v[0] = new unoidl.com.sun.star.beans.PropertyValue();
v[0].Name = "InputStream";
v[0].Value = new uno.Any(typeof(unoidl.com.sun.star.io.XInputStream), OOInputStream.FromFile(tempFile));
unoidl.com.sun.star.graphic.XGraphic graphic = xGraphicProvider.queryGraphic(v);
if (graphic == null) return;
// 
unoidl.com.sun.star.text.XTextContent xTextContent = servfac.createInstance("com.sun.star.text.GraphicObject") as unoidl.com.sun.star.text.XTextContent;
unoidl.com.sun.star.beans.XPropertySet xprops = (unoidl.com.sun.star.beans.XPropertySet)xTextContent;
xprops.setPropertyValue("Width", new uno.Any(imgwid));
xprops.setPropertyValue("Height", new uno.Any(imght));
xprops.setPropertyValue("AnchorType", new uno.Any((int)TextContentAnchorType.AS_CHARACTER));
xprops.setPropertyValue("Graphic", new uno.Any(typeof(unoidl.com.sun.star.graphic.XGraphic), graphic));
// 
XController xController = ((XModel)xComponent).getCurrentController();
unoidl.com.sun.star.view.XSelectionSupplier xSelectionSupplier = xController as unoidl.com.sun.star.view.XSelectionSupplier;
xSelectionSupplier.select(new uno.Any(typeof(unoidl.com.sun.star.text.XTextRange), txtrange));

unoidl.com.sun.star.text.XText xText = txtrange.getText();
unoidl.com.sun.star.text.XTextCursor xTextCursor = xText.createTextCursor();
xTextCursor.gotoRange(txtrange, false);

[b]xText.insertTextContent(xTextCursor, xTextContent, false); [/b] // on this line rises the exception

best regards
Daniel Junges
Last edited by robleyd on Mon May 22, 2023 11:34 am, edited 1 time in total.
User avatar
robleyd
Moderator
Posts: 5082
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Insert image cause IIS crach

Post by robleyd »

The chances of a LO developer reading this message is very small. You might be better asking on the AskLibreOffice site, or via the LO developer mailing list.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
Cazer
Posts: 53
Joined: Mon May 15, 2023 11:55 am

Re: Insert image cause IIS crach

Post by Cazer »

Hi @djunges, it's indeed a tricky situation. It sounds like a thread conflict issue, a common problem with applications using COM objects in a multi-threaded environment like IIS.
The LO API might not be entirely thread-safe, causing exceptions when used within IIS. You could try synchronizing calls to the API, or create a separate process for the LO operations, communicating via IPC.
As @robleyd suggested, reaching out to the LO developers through their mailing list or the AskLibreOffice site might yield more detailed responses. Best of luck solving this issue!
OpenOffice 4.1.14
OS
Post Reply