https://bugs.documentfoundation.org/show_bug.cgi?id=148857
Bug ID: 148857 Summary: Handle is not initialized exception when bootstrapping with .Net (but not in .Net Framework) Product: LibreOffice Version: 7.3.1.3 release Hardware: x86-64 (AMD64) OS: Windows (All) Status: UNCONFIRMED Severity: normal Priority: medium Component: sdk Assignee: libreoffice-bugs@lists.freedesktop.org Reporter: mloc...@gmail.com Description: Bootstrapping in .Net (tested with .Net 6) fails, whereas bootstrapping in .Net Framework (tested with .Net Framework 4.8) succeeds. Consider this C# code: static int Main() { string programPath = GetProgramPath(); System.Environment.SetEnvironmentVariable( "UNO_PATH", programPath, System.EnvironmentVariableTarget.Process ); System.Environment.SetEnvironmentVariable( "URE_BOOTSTRAP", $"vnd.sun.star.pathname:{System.IO.Path.Combine(programPath, "fundamental.ini")}", System.EnvironmentVariableTarget.Process ); System.Environment.SetEnvironmentVariable( "PATH", $"{programPath}{System.IO.Path.PathSeparator}{System.Environment.GetEnvironmentVariable("PATH")}", System.EnvironmentVariableTarget.Process ); try { uno.util.Bootstrap.defaultBootstrap_InitialComponentContext(); System.Console.Out.WriteLine("OK!"); return 0; } catch (System.Exception x) { System.Console.Error.WriteLine(x.GetType().FullName); System.Console.Error.WriteLine(x.Message); System.Console.Error.WriteLine(x.StackTrace); return 1; } } static string GetProgramPath() { var programPath = Microsoft.Win32.Registry.GetValue( Microsoft.Win32.Registry.LocalMachine.Name + @"\SOFTWARE\LibreOffice\UNO\InstallPath", "", null ) as string; if (string.IsNullOrEmpty(programPath)) { throw new System.Exception("Failed to detect the program path"); } return programPath; } When executed with .Net Framework 4.8 everything works just fine. When executed with .Net 6 we have: System.InvalidOperationException Handle is not initialized. at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value) at uno.util.to_cli<class com::sun::star::uno::XComponentContext>(Reference<com::sun::star::uno::XComponentContext>* x) at uno.util.Bootstrap.defaultBootstrap_InitialComponentContext(String ini_file, IDictionaryEnumerator bootstrap_parameters) at uno.util.Bootstrap.defaultBootstrap_InitialComponentContext() at ConsoleDotNetFramework.Program.Main() in Program.cs:line 26 I tested it with LibreOffice 7.3.1.3 and with a fresh built of master (as of 2022-03-28): same results. I also tested it in a Windows Sandbox: same results. Steps to Reproduce: 1. Create a .Net (not .Net Framework) project 2. Add references to the DLLs that come with the SDK 3. Call uno.util.Bootstrap.defaultBootstrap_InitialComponentContext(); Actual Results: defaultBootstrap_InitialComponentContext throws a System.InvalidOperationException exception: Message: Handle is not initialized. Stack trace: at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value) at uno.util.to_cli<class com::sun::star::uno::XComponentContext>(Reference<com::sun::star::uno::XComponentContext>* x) at uno.util.Bootstrap.defaultBootstrap_InitialComponentContext(String ini_file, IDictionaryEnumerator bootstrap_parameters) at uno.util.Bootstrap.defaultBootstrap_InitialComponentContext() Expected Results: defaultBootstrap_InitialComponentContext should return a unoidl.com.sun.star.uno.XComponentContext instance without throwing an exception. Reproducible: Always User Profile Reset: Yes Additional Info: I published a simple Visual Studio solution to showcase this: see https://github.com/mlocati/libreoffice-uno-dotnet The .Net project fails, the .NetFramework project succeeds (with exactly the same code) -- You are receiving this mail because: You are the assignee for the bug.