C# - Windows forms with Gecko and xul

0

I've some problem with integrating Gecko in C# with XUL.

1/I've downloaded geckofx45.45.0.34.nupkg. With that, I've renamed its extension in '.zip' and unzipped this folder. I've got many directory.

2/Then, I've created a windows forms application in C# (.NET Framework 4.5.2). Through 'solution explorer', I've added two libraries (Geckofx-Core.dll and Geckofx-Winforms.dll) generated by step 1

3/Then, in the toolbox , on 'All Windows Forms' collapse, I've done a right click and 'Choose Items'. Then, in '.NET Framework Components' tab, I've added Geckofx-Winforms.dll.

4/I've restarted Visual Studio 2015

5/Then, I've opened again my project and added a 'GeckoBrowser' component from the toolbox to my window.

6/Then, I've compiled my project. It's all right. But, when I've tried to execute my application, I've had a problem :

An unhandled exception of type 'System.DllNotFoundException' occurred in Geckofx-Core.dll
Additional information: Unable to load DLL 'xul': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

So, I've downloaded xulrunner on http://ftp.mozilla.org/pub/xulrunner/releases/latest/runtimes/xulrunner-41.0.2.en-US.win32.zip and unzipped the file. Result : C:\xulrunner\xulrunner-41.0.2.en-US.win32\xulrunner\

7/ Then, in the properties of my project, in 'Reference Paths', I've added the path C:\xulrunner\xulrunner-41.0.2.en-US.win32\xulrunner\

8/ I've launched again my application and always the same error on the screen

I've also tried to use 'TlbImp.exe' without success.

Can you help me ?

c#
xul
gecko
xulrunner
geckofx
asked on Stack Overflow Apr 11, 2018 by user2274060

1 Answer

0

The approach that I use requires dropping the xulrunner folder into the app folder and then using this method:

private void InitializeGeckoEngine()
    {

        try
        {
            if (!Directory.Exists(Paths.XulRunner))
            {
                MessageBox.Show($"Firefox folder not found at {Paths.XulRunner}!");
            }

            Xpcom.EnableProfileMonitoring = false;
            Xpcom.Initialize(Paths.XulRunner);

        }
        catch (Exception ex)
        {
            MessageBox.Show($"Firefox engine not detected or was not loaded correctly. Loading path: {Paths.XulRunner}. Exception details:\n" + ex + ex.InnerException, "Error",
                MessageBoxButton.OK, MessageBoxImage.Error);

        }
    }

The key part is of course the Xpcom.Initialize() call.

answered on Stack Overflow Apr 12, 2018 by Bartosz

User contributions licensed under CC BY-SA 3.0