Bug 163072 - Net8 C# Handle is not initialized
Summary: Net8 C# Handle is not initialized
Status: REOPENED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
24.2.0.3 release
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: .NET
  Show dependency treegraph
 
Reported: 2024-09-21 07:17 UTC by liujian
Modified: 2024-11-25 04:21 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Testcode (1.60 KB, application/x-7z-compressed)
2024-09-21 07:28 UTC, liujian
Details
TESTCode (1.61 KB, application/x-7z-compressed)
2024-09-21 07:29 UTC, liujian
Details
dll (254.40 KB, application/x-7z-compressed)
2024-09-21 07:29 UTC, liujian
Details

Note You need to log in before you can comment on or make changes to this bug.
Description liujian 2024-09-21 07:17:57 UTC
Description:
Microsoft cross-platform framework NetCore, I use the version of Net8, and according to the online tutorial using cli_basetypes.dll,cli_cppuhelper.dll and other 5 DLLS, The error is that the Handle is not initialized. This works fine in the Net FrameWork. I don't know if this is my fault or not supporting the NetCore platform. This is machine translation, there may be errors,all of the following are machine translations,, if there is any problem, please let me know


Steps to Reproduce:
1.  To execute code unoidl.com.sun.star.uno.XComponentContext xLocalContext = the Bootstrap. The Bootstrap (); // Bootstrap.bootstrap();

2.
3.

Actual Results:
System.InvalidOperationException:“Handle is not initialized.”


Expected Results:
It should not report errors like the NetFrameWork. Normal execution


Reproducible: Always


User Profile Reset: No

Additional Info:
Load context
Comment 1 liujian 2024-09-21 07:28:45 UTC
Created attachment 196577 [details]
Testcode
Comment 2 liujian 2024-09-21 07:29:08 UTC
Created attachment 196578 [details]
TESTCode
Comment 3 liujian 2024-09-21 07:29:29 UTC
Created attachment 196579 [details]
dll
Comment 4 Hossein 2024-09-21 07:39:39 UTC
You are using the incorrect version of .NET binding, which is for older versions of .NET framework. The old binding does not work with cross platform .NET.

But I have some good news: the new .NET binding for cross platform .NET has just landed in master, and in order to use it, you need to compile LibreOffice from sources, or use daily builds:

https://dev-builds.libreoffice.org/daily/master/current.html

To get started, look into SDK examples:

https://git.libreoffice.org/core/+/refs/heads/master/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact/csharp/

https://git.libreoffice.org/core/+/refs/heads/master/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/

https://git.libreoffice.org/core/+/refs/heads/master/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape/csharp/

https://git.libreoffice.org/core/+/refs/heads/master/odk/examples/dotnet/WriterDemo

Please take a look at this minimal code from FirstUnoContact example:

using System;
using com.sun.star.lang;
using com.sun.star.uno;
try
{
    XComponentContext xContext = NativeBootstrap.bootstrap();
    Console.WriteLine("Connected to a running office...");
    XMultiComponentFactory xMCF = xContext.getServiceManager();
    Console.WriteLine("Remote service manager is {0}", xMCF is null ? "not available" : "available");
    return 0;
}
catch (UnoException e)
{
    Console.Error.WriteLine(e.Message);
    return 1;
}

It uses NativeBootstrap.bootstrap().
Comment 5 Hossein 2024-09-21 07:50:12 UTC

*** This bug has been marked as a duplicate of bug 148857 ***
Comment 6 liujian 2024-09-23 17:31:18 UTC
(In reply to Hossein from comment #4)
> You are using the incorrect version of .NET binding, which is for older
> versions of .NET framework. The old binding does not work with cross
> platform .NET.
> 
> But I have some good news: the new .NET binding for cross platform .NET has
> just landed in master, and in order to use it, you need to compile
> LibreOffice from sources, or use daily builds:
> 
> https://dev-builds.libreoffice.org/daily/master/current.html
> 
> To get started, look into SDK examples:
> 
> https://git.libreoffice.org/core/+/refs/heads/master/odk/examples/
> DevelopersGuide/FirstSteps/FirstUnoContact/csharp/
> 
> https://git.libreoffice.org/core/+/refs/heads/master/odk/examples/
> DevelopersGuide/FirstSteps/FirstLoadComponent/csharp/
> 
> https://git.libreoffice.org/core/+/refs/heads/master/odk/examples/
> DevelopersGuide/FirstSteps/HelloTextTableShape/csharp/
> 
> https://git.libreoffice.org/core/+/refs/heads/master/odk/examples/dotnet/
> WriterDemo
> 
> Please take a look at this minimal code from FirstUnoContact example:
> 
> using System;
> using com.sun.star.lang;
> using com.sun.star.uno;
> try
> {
>     XComponentContext xContext = NativeBootstrap.bootstrap();
>     Console.WriteLine("Connected to a running office...");
>     XMultiComponentFactory xMCF = xContext.getServiceManager();
>     Console.WriteLine("Remote service manager is {0}", xMCF is null ? "not
> available" : "available");
>     return 0;
> }
> catch (UnoException e)
> {
>     Console.Error.WriteLine(e.Message);
>     return 1;
> }
> 
> It uses NativeBootstrap.bootstrap().

Hi, I downloaded the daily build LibreOfficeDev_25.2.0.0.alpha0_Win_x86-64 and added the dll but I did not find the NativeBootstrap class. Do I need to add new DLLS other than cli_cppuhlper.dll and cli_ure, or do I need to wait for the next official version? This is machine translation, there may be errors
Comment 7 Ritobroto Mukherjee 2024-09-25 08:40:34 UTC
(In reply to liujian from comment #6)
> Hi, I downloaded the daily build LibreOfficeDev_25.2.0.0.alpha0_Win_x86-64
> and added the dll but I did not find the NativeBootstrap class. Do I need to
> add new DLLS other than cli_cppuhlper.dll and cli_ure, or do I need to wait
> for the next official version? This is machine translation, there may be
> errors

Hello. The dev builds don't seem to contain the nuget package for some reason, will have a look into that. Apart from this, you could either wait for the next official version or build LO from source, depending on your requirements. (A version of LO built with the --with-dotnet option will be needed for the bindings to work)

The docs haven't been updated just yet to show the necessary steps to consume the new bindings, but the rough steps are:
1. Build LO locally with the --with-dotnet option, or get a daily or official release with the new bindings
2. Enable the LO SDK with the setsdkenv_windows or setsdkenv_unix script in <LO path>/sdk/
3. Create a .NET 8 project, and add these lines to your .csproj file:

<PropertyGroup>
    <RestoreAdditionalProjectSources>[LO path]/sdk/dotnet</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
    <PackageReference Include="LibreOffice.Bindings" Version="0.1.0" />
</ItemGroup>
Comment 8 liujian 2024-09-25 08:52:24 UTC
Thanks for your answer, I will try to compile libreoffice
Comment 9 liujian 2024-11-20 14:17:14 UTC
(In reply to Ritobroto Mukherjee from comment #7)
> (In reply to liujian from comment #6)
> > Hi, I downloaded the daily build LibreOfficeDev_25.2.0.0.alpha0_Win_x86-64
> > and added the dll but I did not find the NativeBootstrap class. Do I need to
> > add new DLLS other than cli_cppuhlper.dll and cli_ure, or do I need to wait
> > for the next official version? This is machine translation, there may be
> > errors
> 
> Hello. The dev builds don't seem to contain the nuget package for some
> reason, will have a look into that. Apart from this, you could either wait
> for the next official version or build LO from source, depending on your
> requirements. (A version of LO built with the --with-dotnet option will be
> needed for the bindings to work)
> 
> The docs haven't been updated just yet to show the necessary steps to
> consume the new bindings, but the rough steps are:
> 1. Build LO locally with the --with-dotnet option, or get a daily or
> official release with the new bindings
> 2. Enable the LO SDK with the setsdkenv_windows or setsdkenv_unix script in
> <LO path>/sdk/
> 3. Create a .NET 8 project, and add these lines to your .csproj file:
> 
> <PropertyGroup>
>     <RestoreAdditionalProjectSources>[LO
> path]/sdk/dotnet</RestoreAdditionalProjectSources>
> </PropertyGroup>
> <ItemGroup>
>     <PackageReference Include="LibreOffice.Bindings" Version="0.1.0" />
> </ItemGroup>


Hello friend, I compiled version 25.0.0.2, here is my configuration file,



--enable-debug

--with-visual-studio=2022

--with-jdk-home=E:\java

--with-external-tar=F:/Source/Libre/lo-externalsrc

-- with - junit = F/Source/Libre/junit - 4.10. The jar

- with - ant - home = F: / Source/Libre/apache ant -- 1.9.5

--enable-pch

--disable-ccache

--enable-dbgutil

--with-strawberry-perl-portable=c:/strawberry

--host=x86_64-pc-cygwin

--without-doxygen

--enable-python=fully-internal

--without-lxml

--with-dotnet



After finishing in F:\Source\Libre\lode\lode\dev\core\instdir\sdk\dotnet, I did not find dotnet directory, only bin and lib directories, what do I do now, this is machine translation, there may be an error
Comment 10 liujian 2024-11-20 14:19:45 UTC
(In reply to liujian from comment #9)
> (In reply to Ritobroto Mukherjee from comment #7)
> > (In reply to liujian from comment #6)
> > > Hi, I downloaded the daily build LibreOfficeDev_25.2.0.0.alpha0_Win_x86-64
> > > and added the dll but I did not find the NativeBootstrap class. Do I need to
> > > add new DLLS other than cli_cppuhlper.dll and cli_ure, or do I need to wait
> > > for the next official version? This is machine translation, there may be
> > > errors
> > 
> > Hello. The dev builds don't seem to contain the nuget package for some
> > reason, will have a look into that. Apart from this, you could either wait
> > for the next official version or build LO from source, depending on your
> > requirements. (A version of LO built with the --with-dotnet option will be
> > needed for the bindings to work)
> > 
> > The docs haven't been updated just yet to show the necessary steps to
> > consume the new bindings, but the rough steps are:
> > 1. Build LO locally with the --with-dotnet option, or get a daily or
> > official release with the new bindings
> > 2. Enable the LO SDK with the setsdkenv_windows or setsdkenv_unix script in
> > <LO path>/sdk/
> > 3. Create a .NET 8 project, and add these lines to your .csproj file:
> > 
> > <PropertyGroup>
> >     <RestoreAdditionalProjectSources>[LO
> > path]/sdk/dotnet</RestoreAdditionalProjectSources>
> > </PropertyGroup>
> > <ItemGroup>
> >     <PackageReference Include="LibreOffice.Bindings" Version="0.1.0" />
> > </ItemGroup>
> 
> 
> Hello friend, I compiled version 25.0.0.2, here is my configuration file,
> 
> 
> 
> --enable-debug
> 
> --with-visual-studio=2022
> 
> --with-jdk-home=E:\java
> 
> --with-external-tar=F:/Source/Libre/lo-externalsrc
> 
> -- with - junit = F/Source/Libre/junit - 4.10. The jar
> 
> - with - ant - home = F: / Source/Libre/apache ant -- 1.9.5
> 
> --enable-pch
> 
> --disable-ccache
> 
> --enable-dbgutil
> 
> --with-strawberry-perl-portable=c:/strawberry
> 
> --host=x86_64-pc-cygwin
> 
> --without-doxygen
> 
> --enable-python=fully-internal
> 
> --without-lxml
> 
> --with-dotnet
> 
> 
> 
> After finishing in F:\Source\Libre\lode\lode\dev\core\instdir\sdk\dotnet, I
> did not find dotnet directory, only bin and lib directories, what do I do
> now, this is machine translation, there may be an error


Enable the LO SDK with the setsdkenv_windows or setsdkenv_unix script in   LO path>/sdk/

I'm not sure how to write it here
Comment 11 Ritobroto Mukherjee 2024-11-24 16:48:13 UTC
> After finishing in F:\Source\Libre\lode\lode\dev\core\instdir\sdk\dotnet, I
> did not find dotnet directory, only bin and lib directories, what do I do
> now, this is machine translation, there may be an error

Could you go into the core/ directory, then run `make net_ure.clean` and `make net_ure` (without the ``) and share the output you obtain?

> Enable the LO SDK with the setsdkenv_windows or setsdkenv_unix script in LO path>/sdk/
> I'm not sure how to write it here

In the sdk/ directory, you should have a batch file named setsdkenv_windows.bat. Running the script in the command line should enable the LO SDK. Explaining how to run examples with it is a little complex over text, but this session by Mr. Hossein covers the basics: https://youtu.be/zWLFv5AR3uY?t=527

However, this won't be useful if the .NET libraries aren't getting installed to the sdk/dotnet directory. Your build output might help in figuring out why.
Comment 12 liujian 2024-11-25 04:15:13 UTC
(In reply to Ritobroto Mukherjee from comment #11)
> > After finishing in F:\Source\Libre\lode\lode\dev\core\instdir\sdk\dotnet, I
> > did not find dotnet directory, only bin and lib directories, what do I do
> > now, this is machine translation, there may be an error
> 
> Could you go into the core/ directory, then run `make net_ure.clean` and
> `make net_ure` (without the ``) and share the output you obtain?
> 
> > Enable the LO SDK with the setsdkenv_windows or setsdkenv_unix script in LO path>/sdk/
> > I'm not sure how to write it here
> 
> In the sdk/ directory, you should have a batch file named
> setsdkenv_windows.bat. Running the script in the command line should enable
> the LO SDK. Explaining how to run examples with it is a little complex over
> text, but this session by Mr. Hossein covers the basics:
> https://youtu.be/zWLFv5AR3uY?t=527
> 
> However, this won't be useful if the .NET libraries aren't getting installed
> to the sdk/dotnet directory. Your build output might help in figuring out
> why.

output:
$ make net_ure. clean
make: Nothing to be done for 'net_ure.'.
rm -fr F:/Source/Libre/lode/lode/dev/core/test-install
rm -fr F:/Source/Libre/lode/lode/dev/core/instdir
rm -fr F:/Source/Libre/lode/lode/dev/core/workdir


$ make net_ure
cd F:/Source/Libre/lode/lode/dev/core/net_ure && C:/Users/Administrator/bin/make -j 12 -rs
[build MOD] net_ure
[build LOC] net_ure
[build BIN] top level modules: net_ure
[build LOC] top level modules: net_ure
[build ALL] top level modules: build-non-l10n-only build-l10n-only
Comment 13 liujian 2024-11-25 04:21:42 UTC
(In reply to liujian from comment #12)
> (In reply to Ritobroto Mukherjee from comment #11)
> > > After finishing in F:\Source\Libre\lode\lode\dev\core\instdir\sdk\dotnet, I
> > > did not find dotnet directory, only bin and lib directories, what do I do
> > > now, this is machine translation, there may be an error
> > 
> > Could you go into the core/ directory, then run `make net_ure.clean` and
> > `make net_ure` (without the ``) and share the output you obtain?
> > 
> > > Enable the LO SDK with the setsdkenv_windows or setsdkenv_unix script in LO path>/sdk/
> > > I'm not sure how to write it here
> > 
> > In the sdk/ directory, you should have a batch file named
> > setsdkenv_windows.bat. Running the script in the command line should enable
> > the LO SDK. Explaining how to run examples with it is a little complex over
> > text, but this session by Mr. Hossein covers the basics:
> > https://youtu.be/zWLFv5AR3uY?t=527
> > 
> > However, this won't be useful if the .NET libraries aren't getting installed
> > to the sdk/dotnet directory. Your build output might help in figuring out
> > why.
> 
> output:
> $ make net_ure. clean
> make: Nothing to be done for 'net_ure.'.
> rm -fr F:/Source/Libre/lode/lode/dev/core/test-install
> rm -fr F:/Source/Libre/lode/lode/dev/core/instdir
> rm -fr F:/Source/Libre/lode/lode/dev/core/workdir
> 
> 
> $ make net_ure
> cd F:/Source/Libre/lode/lode/dev/core/net_ure &&
> C:/Users/Administrator/bin/make -j 12 -rs
> [build MOD] net_ure
> [build LOC] net_ure
> [build BIN] top level modules: net_ure
> [build LOC] top level modules: net_ure
> [build ALL] top level modules: build-non-l10n-only build-l10n-only

I installed the net8 sdk

The previous input configuration file --with-dotnet=C:/Program Files/dotnet/dotnet.exe should look like this. What am I doing wrong?