I am using this a few DLLS to connect libreoffice. I am using the c #,.net core 8.0, but he complains: System. InvalidOperationException: "Handle is not initialized.". Error code: m_xContext = uno. Util. The Bootstrap, Bootstrap ();
But my use of the net framework is fine. May I ask where the operation is not in place, what is the solution? I use machine translation, translation may be wrong
C# Net 8 handle is not initialized
C# Net 8 handle is not initialized
- Attachments
-
- code.7z
- (4.87 KiB) Downloaded 45 times
-
- 图片1.png (17.76 KiB) Viewed 1747 times
-
- 图片2.png (85.14 KiB) Viewed 1747 times
win11 libreoffice 24.8.0.3
Re: C# Net 8 handle is not initialized
Please insert your complete code as text, not as picture
In your text you mention Libreoffice, in your footer Openoffice. What is true?
32 bit or 64 bit version for LO?
In your text you mention Libreoffice, in your footer Openoffice. What is true?
32 bit or 64 bit version for LO?
Re: C# Net 8 handle is not initialized
1 Are libreoffice and openoffice the same product?
2 Code I downloaded from libreoffice example, a bit much, the previous package has been uploaded. Upload file I encountered cs file can not upload, upload file number limit
3 I use vs2022 netframework x64 properly, 32 has problems. Both net8 x64 and 32 have problems.
win11 libreoffice 24.8.0.3
Re: C# Net 8 handle is not initialized
Hi,
this is a very simple example. Try to get this running ...
this is a very simple example. Try to get this running ...
Code: Select all
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Threading;
using unoidl.com.sun.star.awt;
using unoidl.com.sun.star.document;
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.bridge;
using unoidl.com.sun.star.frame;
using unoidl.com.sun.star.sheet;
using unoidl.com.sun.star.beans;
using unoidl.com.sun.star.container;
using unoidl.com.sun.star.drawing;
using unoidl.com.sun.star.embed;
using unoidl.com.sun.star.table;
using unoidl.com.sun.star.text;
using unoidl.com.sun.star.util;
namespace CSharpDemo {
public class OpenOfficeApp {
[STAThread]
public static void Main() {
Console.WriteLine("CSharpDemo Start");
// create the desktop
XComponentContext XCC = uno.util.Bootstrap.bootstrap();
XMultiComponentFactory XMCF = (XMultiComponentFactory)XCC.getServiceManager();
XMultiServiceFactory XMSF1 = (XMultiServiceFactory)XCC.getServiceManager();
XComponentLoader XCL = (XComponentLoader)XMSF1.createInstance("com.sun.star.frame.Desktop");
// open the spreadsheet document
PropertyValue[] pPV = new PropertyValue[2];
pPV[0] = new PropertyValue();
pPV[0].Name = "Hidden";
pPV[0].Value = new uno.Any(false);
pPV[1] = new PropertyValue();
pPV[1].Name = "ReadOnly";
pPV[1].Value = new uno.Any(false);
XComponent XCo = XCL.loadComponentFromURL("private:factory/scalc","_blank",0,pPV);
}
}
}
Re: C# Net 8 handle is not initialized
ms777 wrote: ↑Sat Sep 21, 2024 12:58 pm Hi,
this is a very simple example. Try to get this running ...Code: Select all
using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Threading; using unoidl.com.sun.star.awt; using unoidl.com.sun.star.document; using unoidl.com.sun.star.lang; using unoidl.com.sun.star.uno; using unoidl.com.sun.star.bridge; using unoidl.com.sun.star.frame; using unoidl.com.sun.star.sheet; using unoidl.com.sun.star.beans; using unoidl.com.sun.star.container; using unoidl.com.sun.star.drawing; using unoidl.com.sun.star.embed; using unoidl.com.sun.star.table; using unoidl.com.sun.star.text; using unoidl.com.sun.star.util; namespace CSharpDemo { public class OpenOfficeApp { [STAThread] public static void Main() { Console.WriteLine("CSharpDemo Start"); // create the desktop XComponentContext XCC = uno.util.Bootstrap.bootstrap(); XMultiComponentFactory XMCF = (XMultiComponentFactory)XCC.getServiceManager(); XMultiServiceFactory XMSF1 = (XMultiServiceFactory)XCC.getServiceManager(); XComponentLoader XCL = (XComponentLoader)XMSF1.createInstance("com.sun.star.frame.Desktop"); // open the spreadsheet document PropertyValue[] pPV = new PropertyValue[2]; pPV[0] = new PropertyValue(); pPV[0].Name = "Hidden"; pPV[0].Value = new uno.Any(false); pPV[1] = new PropertyValue(); pPV[1].Name = "ReadOnly"; pPV[1].Value = new uno.Any(false); XComponent XCo = XCL.loadComponentFromURL("private:factory/scalc","_blank",0,pPV); } } }
I have tried this similar code and it works in the NetFramework, but it doesn't work in NetCore
ERROR CODE: XComponentContext XCC = uno.util.Bootstrap.bootstrap();
win11 libreoffice 24.8.0.3
Re: C# Net 8 handle is not initialized
When working with NetCore, you probably have to link the correct windows dlls. I cannot help you there, sorry. I use csc.exe, see the PowerShell script to get an idea
Code: Select all
param([string]$fileName, [string]$fileNameWithoutExt)
$csc = 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe'
$cliPath = 'C:\Program Files\LibreOffice\sdk\cli\'
$fileNameExe = "$($fileNameWithoutExt).exe"
if (Test-Path $fileNameExe -PathType Leaf ) {
rm $fileNameExe
}
$cmdPars = @('/nologo', '-warnaserror+', '-debug+')
('cli_basetypes', 'cli_uretypes', 'cli_oootypes', 'cli_ure', 'cli_cppuhelper') | foreach{$cmdPars += "-reference:$($cliPath)$($_).dll"}
$cmdPars += $fileName
. $csc $cmdPars
if (Test-Path $fileNameExe -PathType Leaf ) {
"compiled successfully"
. ".\$($fileNameExe)"
}