Probable .Net Core SHK issues

Ilya Sokolov is at rula-tech.com
Tue Apr 1 10:00:00 UTC 2025


Hello,

I successfully managed to run the WriterDemo example and to connect to the
Libre Office from my application.
The differences between the .Net Core API and the API used for .Net
Framework are astonishing.

Could you tell me if there is an example of how to get Libre Office version
if .Net? I have code which worked with the .net framework, but now the
code, listed below, does not work:


Any[] VerRequest = new Any[1];


VerRequest[0] = new Any(typeof(PropertyValue), new PropertyValue()

{

Name = "nodepath",

Value = new Any("/org.openoffice.Setup/Product")

});


XMultiServiceFactory ConfProvider =
m_HnComponentContext.getServiceManager().query<XMultiServiceFactory>();
if (ConfProvider != null)
{

XNameAccess ConfAccess =
(XNameAccess)ConfProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess",
VerRequest);

if (ConfAccess != null)

{

return ConfAccess.getByName("ooSetupVersion").Value as string;

}

}


Besides, there are another couple of issues regarding the SDK. The first is
an error while setting up a proprety of a font. The code (modification of
the WriterDemo.cs example) is shown below:

// Create a cursor object
XTextCursor cursor = simpleText.createTextCursor();


cursor.query<XPropertySet>().setPropertyValue("CharWeight", new
Any(((float)200)));
cursor.query<XPropertySet>().setPropertyValue("CharEscapement", new
Any((Int16)0));
cursor.query<XPropertySet>().setPropertyValue("CharEscapementHeight", new
Any((Byte)100));



// Inserting some Text
text.insertString(cursor, "The first line in the newly created text
document.\n", false);


The 'Object reference not set to an instance of an object.' occurs on the
cursor.query<XPropertySet>().setPropertyValue("CharEscapementHeight", new
Any((Byte)100)); line.

The second issue occures while setting up with of table colimns. The code
(modification of the same example) is shown below:

void SetColumnWidth(XTextTable textTable,int ColNum, short Width)
{

Any obj =
textTable.query<XPropertySet>().getPropertyValue("TableColumnSeparators");

TableColumnSeparator[] tcs = (TableColumnSeparator[])(obj.Value);

short Delta = 0;

if (tcs != null)

{

if (tcs.Length - 1 >= ColNum)

{

if (ColNum == 0)

{

Delta = (short)(Width - tcs[ColNum].Position);

tcs[ColNum].Position = Width;

}

else

{

Delta = (short)(Width - (tcs[ColNum].Position - tcs[ColNum].Position));

tcs[ColNum].Position = (short)(Width + tcs[ColNum - 1].Position);

}

}


Any val = new Any(typeof(com.sun.star.text.TableColumnSeparator[]), tcs);

textTable.query<XPropertySet>().setPropertyValue("TableColumnSeparators",
val);

}

}

If the function is called in
\sdk\examples\dotnet\WriterDemo\csharp\WriterDemo.cs, like listed below:

// Get first row
XTableRows tableRows = textTable.getRows();
Any rowAny = tableRows.query<XIndexAccess>().getByIndex(0);


SetColumnWidth(textTable, 1, 200);


// Set a different background color for the first row
XPropertySet firstRowPropertySet = rowAny.cast<XPropertySet>();
firstRowPropertySet.setPropertyValue("BackTransparent", new Any(false));



It gives an access violation error ("Attempted to read or write protected
memory. This is often an indication that other memory is corrupt") on the
line

textTable.query<XPropertySet>().setPropertyValue("TableColumnSeparators",
val);

When I tried to get the columns of the table via the code below (the code
is inserted in the  WriterDemo.cs  example too):

// Set the table background color
XPropertySet tablePropertySet = textTableI.query<XPropertySet>();
tablePropertySet.setPropertyValue("BackTransparent", new Any(false));
tablePropertySet.setPropertyValue("BackColor", new Any(0xCCCCFF));


XTableColumns tableCols = textTable.getColumns();
Any colAny = tableCols.query<XIndexAccess>().getByIndex(1);


// Get first row
XTableRows tableRows = textTable.getRows();
Any rowAny = tableRows.query<XIndexAccess>().getByIndex(0);



However, the   tableCols.query<XIndexAccess>().getByIndex(1) line give
another error:

Exception thrown: 'System.ArgumentException' in net_basetypes.dll
An unhandled exception of type 'System.ArgumentException' occurred in
net_basetypes.dll
Value of Any can only be null if Type is void. Perhaps you want Any.VOID?


Could you tell me what is a proper way to change the table column width
using the .Net Core SDK?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20250401/0240553b/attachment.htm>


More information about the LibreOffice mailing list