Trouble using UNOIDL library in C# on Windows 11: uno.Any[] argsArray = new uno.Any[] { new uno.Any(context)};

Greetings everyone again, i have another problem linked to UNOIDL library and C#.
I wrote this function

public static object[] Load_LO_calc_file_complete(string filePath, PropertyValue[] loadProps)
{
         //==================================================
          XComponentContext context = uno.util.Bootstrap.bootstrap();
          XMultiComponentFactory xMSF = context.getServiceManager();
          uno.Any[] argsArray = new uno.Any[] { new uno.Any(context)};
          XDesktop desktop = (XDesktop)xMSF.createInstanceWithArgumentsAndContext("com.sun.star.frame.Desktop", argsArray, context);
          XComponentLoader componentLoader = (XComponentLoader)desktop;
           XComponent calcDoc = componentLoader.loadComponentFromURL("file:///" + filePath, "_blank", 0, loadProps);
          XModel xModel = (XModel)calcDoc; // Ottieni XModel dal documento
          XSpreadsheetDocument xSpreadsheetDocument = (XSpreadsheetDocument)calcDoc;
          XSpreadsheets spreadsheets = xSpreadsheetDocument.getSheets();
          XIndexAccess sheetsIndex = (XIndexAccess)spreadsheets;
          XSpreadsheet currentSheet = (XSpreadsheet)sheetsIndex.getByIndex(0).Value;
          string activeSheetName = Get_active_sSheet_name(calcDoc);
          XPrintable printDocument = (XPrintable)calcDoc;
          // Prepare objects for return
          object[] references = {
          context,
          xMSF,
          desktop,
          componentLoader,
          calcDoc,
          xSpreadsheetDocument,
          xModel,
          spreadsheets,
          sheetsIndex,
          currentSheet,
          activeSheetName,
          printDocument};
          return references;
}

But I’ve some problems with this instruction (context):
uno.Any[] argsArray = new uno.Any[] { new uno.Any(context)};
the error:
Error CS1503 Argument 1: cannot convert from ‘unoidl.com.sun.star.uno.XComponentContext’ to ‘char’
I don’t understand the error and i don’t know what to do . Does anyone smarter than me have any ideas?
Thank you in advance :blush:

[erAck: edited to format code as code, see This is the guide - How to use the Ask site? - #6 by erAck]

I apologize for not having followed the rules; I’m a novice! :grimacing:I’m very grateful to you for the correction. :blush:

Hi,
1st: Replace

uno.Any[] argsArray = new uno.Any[] { new uno.Any(context)};

by

uno.Any[] argsArray = new uno.Any[] { new uno.Any(typeof(XComponentContext), context)};

This will remove the compilation error.

2nd: In

xMSF.createInstanceWithArgumentsAndContext("com.sun.star.frame.Desktop", argsArray, context);

it does not really make sense to put the context into the argsArray. The context is already passed as the third parameter. I do not believe that arguments are needed to instantiate Desktop. It works also when argsArray is null

3rd: In general, if you are not yet familiar with the uno object model I recommend to get something working in LOBasic, and then translate to c#. The former is relatively well documented and you find many examples and much help in the forum. The latter is poorly documented and not very well supported in the forum

Good luck,

ms777

P.S.: And sometimes RTFM…
https://www.openoffice.org/api/docs/java/ref/com/sun/star/uno/Any.html#Any(com.sun.star.uno.Type,%20java.lang.Object)
https://www.openoffice.org/api/docs/common/ref/com/sun/star/lang/XMultiComponentFactory.html#createInstanceWithArgumentsAndContext

Thank you for the solution and your kindness. Have good day :blush:

… always a pleasure