I'm using the MozNet plugin from Se7enSoft. This is a WebBrowser control for FireFox 3.6. It uses XulRunner.
The first thing I have to do is to execute an Initialize(...) method.
var binDirectory = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location);
var xulRuntimeDirectory = Path.Combine(binDirectory, "xul");
Se7enSoft.MozNet.Xpcom.Initialize(xulRuntimeDirectory, null);
I have to pass it the directory into which we've installed XulRunner. The Initialize method of this plugin internally uses the following DLLImport.
[DllImport("xpcom", CharSet = CharSet.Ansi,
EntryPoint = "NS_CStringContainerFinish",
CallingConvention = CallingConvention.Cdecl)]
internal static extern int Moz_CStringContainerFinish(ACString container);
The NS_CStringContainerFinish method from the XulRunner's xpcom.dll is required.
Just before this method is called the very first time, the MozNet plugin temporarily changes the PATH environment variable.
Environment.SetEnvironmentVariable("path",
Environment.GetEnvironmentVariable("path") + ";" +
binDirectory, EnvironmentVariableTarget.Process);
The XulRunner's location is temporarily added to the PATH environment variable to make sure it can resolve the xpcom.dll (and others).
However it still cannot find it. I'm receiving the following exception.
Unable to load DLL 'xpcom': Cannot find method.
(Exception from HRESULT: 0x8007007F)
at Se7enSoft.MozNet.Native.MozNativeMethods.Moz_CStringContainerInit(
ACString container)
at Se7enSoft.MozNet.Xpcom.XpCom_Init()
at Se7enSoft.MozNet.Xpcom.Initialize(String mozPath, String profPath)
This problem only occurs on 3 PC's (Windows 2000 & XP). Works fine for hundreds of others.
I can reproduce the problem if I debug and step over the Environment.SetEnvironmentVariable(...) method.
Are there any issues with SetEnvironmentVariable that might prevent it from changing the PATH environment variable?