Mac OS X, C#/Mono - GeckoFX "System.DllNotFoundException: xul" - c#

I have an application which utilizes GeckoFX/xulrunner 22.
This program works great in Windows but no matter what I do I cannot get it to run in Linux nor Mac.
The primary focus is Mac though.
I've tried swapping out different versions of Windows, Linux & Mac xulrunner run-times as well as different initialization strings to try including both the Windows, Linux and Mac versions (of course only one at a time) like:
Gecko.Xpcom.Initialize("lib/xulrunner");
Gecko.Xpcom.Initialize("lib/XUL.framework/Versions/Current");
I have also tried prefixing with "./" as well as using code to obtain the current working directory to prepend to the path.
I've also tried copying over a dozen different versions of xul.dll into the executable folder and subdirectories within it.
No matter what I think to try, or search this site/google to try nothing has worked.
This is failing on the Initialize() call.
The program/class names are only starred out so this is not the first thing popping up in google when people search for the program.
Although my biggest concern is getting this running on Mac, I will also mention due to other posts on Stack Overflow and alike that on my Linux system, I have tried having various versions of Firefox installed and the path pointed to as per other peoples' instructions. It always shows the same error as on Mac.
Error follows: Unhandled Exception:
System.DllNotFoundException: xul
at (wrapper managed-to-native) Gecko.Xpcom:Alloc (intptr)
at Gecko.nsAString..ctor () [0x00000] in :0
at Gecko.nsAString..ctor (System.String value) [0x00000] in :0
at Gecko.Xpcom.Initialize (System.String binDirectory) [0x00000] in :0
at **********.**********.CreateBrowsers () [0x00000] in :0
at **********.**********.**********_Shown (System.Object sender, System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.OnShown (System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.SetVisibleCore (Boolean value) [0x00000] in :0
at System.Windows.Forms.Control.set_Visible (Boolean value) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:set_Visible (bool)
at System.Windows.Forms.Application.RunLoop (Boolean Modal, System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.Form mainForm) [0x00000] in :0
at **********.Program.Main () [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: xul
at (wrapper managed-to-native) Gecko.Xpcom:Alloc (intptr)
at Gecko.nsAString..ctor () [0x00000] in :0
at Gecko.nsAString..ctor (System.String value) [0x00000] in :0
at Gecko.Xpcom.Initialize (System.String binDirectory) [0x00000] in :0
at **********.**********.CreateBrowsers () [0x00000] in :0
at **********.**********.**********_Shown (System.Object sender, System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.OnShown (System.EventArgs e) [0x00000] in :0
at System.Windows.Forms.Form.SetVisibleCore (Boolean value) [0x00000] in :0
at System.Windows.Forms.Control.set_Visible (Boolean value) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:set_Visible (bool)
at System.Windows.Forms.Application.RunLoop (Boolean Modal, System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext context) [0x00000] in
:0
at System.Windows.Forms.Application.Run (System.Windows.Forms.Form mainForm) [0x00000] in :0
at **********.Program.Main () [0x00000] in :0

Firstly, to my knowledge no one has ever run geckofx on OSX.
The problem you are seeing is probably easy fixable but before getting geckofx to work on mac you will likely hit more problems.
Geckofx's architecture on Windows is simple. The GeckoWebBrowser control is a winforms based control, which underneath are win32 controls and gecko/firefox on windows also uses win32 controls.
However on Linux things are a little more complicated as gecko/firefox uses GTK while the mono winform implementation is based upon X11. Hence geckofx has some fairly complex code to make that all work. (Which is why one needs to use a different build of geckofx on Linux (one with the GTK flag defined).
So firstly on OSX you have to determine what UI toolkit does mono uses for winforms, is it X11, carbon or something else? Then you have to determine which toolkit Firefox uses on OSX, carbon, cocoa or something else? If they happen to match then its probably worth proceeding with the windows build of geckofx. If they are different then you will probably have to modify geckofx itself to deal with this issue.
Now on to the DllNotFoundException.
The PInvoke/DllImport calls are probably looking for "xul.dll". This file could be named something different in OSX's firefox (eg. libxul.so) so a dllmap config file is needed to map xul.dll to the correct file.
Also setting these two environment variables, MONO_LOG_LEVEL="debug" and MONO_LOG_MASK="dll" should provide you with useful debug information.
Additionally one can use an absolute path for Gecko.Xpcom.Initialize to avoid any confusion about finding the path.

Related

How can I use .NET framework 4.5 in Unity 5

I'm working with unity3D 5. And I wanna import external my KinectDB.dll (includes my sql server db functions with entityframework. And it was complied with .NET 4.5 framework) class library to unity. But unity console gives me an error like below. I searched for this problem many hours. But I can't reach to complete solution. How can I solve this? What are your advices? Thanks in advance.
Hint : I created an example project with .NET 3.5 framework. And I import it to unity. Unity doesnt give me an error in this case.
Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0
at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0
at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0
at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
Missing method .ctor in assembly -------\Assets\KinectDB.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
The class System.Runtime.Versioning.TargetFrameworkAttribute could not be loaded, used in KinectDB
Can't find custom attr constructor image: Assets\KinectDB.dll mtoken: 0x0a00000e
You can only wait till Unity updates its bundled Mono to 4.x. It is already on their roadmap. With Microsoft licenses Mono runtime from LGPL to MIT and Unity joined .NET Foundation, it is likely that such a platform upgrade might come sooner.
http://unity3d.com/unity/roadmap
Yeah. It all starts with reading the documentation - and realizing that Unity uses a quite outdated version of .NET. You CAN NOT use 4.5 libraries in Unity. What you CAN do is run them in a separate program and communicate with this program via network etc. - but that is a LOT of work.
Once in the future Unity will upgrade. But they have not yet.

Running simple winforms application on Mono for ARM

I am currently trying to set up an environment in which I can create winform applications with Visual Studio 2013 that I then want to put on an ARM v7 BeagleBone Black with an attached touchscreen where they are supposed to run with Mono.
In order to do so, I took a Ubuntu 14.10 AMD64 system and created a cross-compile environment with the BeagleBone Black's toolchain and scratchbox2.
I verified that the toolchain an sb2 work correctly by compiling some native test programs with it, they do run flawlessly on the Ubuntu machine (with sb2) as well as on the BeagleBone Black.
Next, I compiled mono from source, once for the Ubuntu machine and also once for the BeagleBone Black. To do so, I mainly followed this post. In the end I had a directory with the complete mono tree whose native components had been correctly compiled for ARM. I verified that by running sb2 mono -V on the Ubuntu system as well as mono -V on the BeagleBone Black after copying the mono directory onto it. I can also run a simple .NET console application that I created with VS2013 on the BBB's mono.
Next I tried to run a simple GUI application that basically only consists of a single form and a button that pops up a messagebox. The project settings in VS were set to .NET Framework version 4.5 and "Release".
Next, I tried to run this EXE with mono on the Ubuntu system and it worked after tweaking the ./configure options, recompiling mono (--with-tls=__thread) and installing the required libraries (libgdiplus and libx11). But when I try to run the same EXE on the BBB it crashes with this exception:
Unhandled Exception:
System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0
at System.Drawing.Bitmap..ctor (Int32 width, Int32 height, PixelFormat format) [0x00000] in <filename unknown>:0
at System.Drawing.Bitmap..ctor (System.Drawing.Image original, Int32 width, Int32 height) [0x00000] in <filename unknown>:0
at System.Drawing.Bitmap..ctor (System.Drawing.Image original, Size newSize) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (System.Drawing.Image,System.Drawing.Size)
at System.Windows.Forms.XplatUIX11.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, Color cursor_pixel, Color mask_pixel, Int32 xHotSpot, Int32 yHotSpot) [0x00000] in <filename unknown>:0
at System.Windows.Forms.XplatUI.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, Color cursor_pixel, Color mask_pixel, Int32 xHotSpot, Int32 yHotSpot) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Cursor.CreateCursor (System.IO.Stream stream) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Cursor..ctor (System.Type type, System.String resource) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Cursors.get_SizeNWSE () [0x00000] in <filename unknown>:0
at System.Windows.Forms.SizeGrip..ctor (System.Windows.Forms.Control CapturedControl) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.SizeGrip:.ctor (System.Windows.Forms.Control)
at System.Windows.Forms.ScrollableControl.CreateScrollbars () [0x00000] in <filename unknown>:0
at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <filename unknown>:0
at System.Windows.Forms.ContainerControl..ctor () [0x00000] in <filename unknown>:0
at System.Windows.Forms.Form..ctor () [0x00000] in <filename unknown>:0
at guitest.Form1..ctor () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) guitest.Form1:.ctor ()
at guitest.Program.Main () [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0
at System.Drawing.Bitmap..ctor (Int32 width, Int32 height, PixelFormat format) [0x00000] in <filename unknown>:0
at System.Drawing.Bitmap..ctor (System.Drawing.Image original, Int32 width, Int32 height) [0x00000] in <filename unknown>:0
at System.Drawing.Bitmap..ctor (System.Drawing.Image original, Size newSize) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (System.Drawing.Image,System.Drawing.Size)
at System.Windows.Forms.XplatUIX11.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, Color cursor_pixel, Color mask_pixel, Int32 xHotSpot, Int32 yHotSpot) [0x00000] in <filename unknown>:0
at System.Windows.Forms.XplatUI.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, Color cursor_pixel, Color mask_pixel, Int32 xHotSpot, Int32 yHotSpot) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Cursor.CreateCursor (System.IO.Stream stream) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Cursor..ctor (System.Type type, System.String resource) [0x00000] in <filename unknown>:0
at System.Windows.Forms.Cursors.get_SizeNWSE () [0x00000] in <filename unknown>:0
at System.Windows.Forms.SizeGrip..ctor (System.Windows.Forms.Control CapturedControl) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Windows.Forms.SizeGrip:.ctor (System.Windows.Forms.Control)
at System.Windows.Forms.ScrollableControl.CreateScrollbars () [0x00000] in <filename unknown>:0
at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <filename unknown>:0
at System.Windows.Forms.ContainerControl..ctor () [0x00000] in <filename unknown>:0
at System.Windows.Forms.Form..ctor () [0x00000] in <filename unknown>:0
at guitest.Form1..ctor () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) guitest.Form1:.ctor ()
at guitest.Program.Main () [0x00000] in <filename unknown>:0
I wonder what the problem might be? How can I go on from here?
BTW: This is the mono version on the BBB:
Mono JIT compiler version 3.12.0 (tarball Mo 23. Feb 11:40:46 CET 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: normal
Notifications: epoll
Architecture: armel,vfp+fallback
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen
Update: I just noticed this little mono utility called mono-test-install. When I run it on the BBB, it tells me this:
./mono-test-install
Active Mono:
Warning: pkg-config could not find mono installed on this system
No dotnet pkgconfig found, Windows.Forms, System.Drawing and others will not work
I think that may be my problem. Does somebody know how to get things on track in this case? I assume that I somehow have to tell mono where it can find its libraries and assemblies, but I can't tell for sure... It would be great if someone could shed some light on this.
Update 2: I was able to get rid of the error shown by mono-test-install by creating the relevant environment variables for my hand-made mono version (described here). Also, I had to edit the file [mono-directory]/usr/local/bin/mcs and correct the paths to the executables. I assume you can set them automatically with PREFIX=... when you configure mono, but I didn't do that.
Now, when I run mono-test-install I get this:
Active Mono: /home/root/monotree_armv7/usr/local/bin/mono
Other Mono executables: /usr/local/bin/mono
Your have a working System.Drawing setup
Your file system watcher is: System.IO.InotifyWatcher
So I think there should be everything in place and set up correctly now. But it still does not work. When I run my little winforms test program, I get the very same exception as given above.
After some searching I found out that there is probably a bug in mono as I am not the first one to run into this. The strange thing however is the fact that the same EXE runs flawlessly on Ubuntu with the very same mono version (just compiled for amd64 and not armv7, same configure options). So on the PC everything works fine, on arm it crashes.
Update: I filed a report with an attached sample project that produces the problems here.
A bit of digging shows that GDI+ GdipCreateBitmapFromScan0 returns InvalidParameter when width or height is a non-positive number.
Going upper the stack trace indicates that Bitmap constructor is called from X11 driver when preferred cursor size (reported by XQueryBestCursor from libX11) differs from original cursor size (which is 32x32 pixels).
So the thought is that XQueryBestCursor() on your BeagleBone returns zero width/height for cursor. A bit of googling gets us to the thread describing a similar issue. There's even some kind of patch there.
I believe you should either recompile X11 on your BeagleBone with a patch provided, or add some checks in mono source (after calling XQueryBestCursor) so it use cursor's original width/height when X11 returns zero width/height.
UPD: HW cursor size seems to be actually reported by video driver, so you can probably just try another one, like recent xf86-video-fbdev.

Trying to connect Unity3d with a DLL that uses SQL Server Compact Missing or incorrect header for method CompileQueryPlan?

I'm working on a Unity3d project that involves Databases,
I wanted the other developer to work on the server's and produce a DLL for me to use in Unity
I tried to work directly in Unity with SqlServerCe but it always stated that it's missing libs
So I managed to load the Backend's DLL successfully in Unity3D (Using v3.5 .Net Client Profile, in both the VS and Unity's Mono Develop)
It initializes the SQL components successfully (reader ... etc)
But when I execute the reader the DLL returns this exception as a string (I handled that when an exception occurs it's returned as a string)
The Exception:
System.InvalidProgramException: Missing or incorrect header for method CompileQueryPlan
at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand (CommandBehavior behavior, System.String method, ResultSetOptions options) [0x00000] in <filename unknown>:0
at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader (CommandBehavior behavior) [0x00000] in <filename unknown>:0
at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Data.SqlServerCe.SqlCeCommand:ExecuteReader ()
at AbuEl3orrefDatabaseBackend.DBHandler.PrepareAllQuestions () [0x00000] in <filename unknown>:0
Well I finally found the solution,
I was on Web Platform, as it doesn't support SQL Server Compact, so I switched to Desktop Platform from the Build Settings.

System.NullReferenceException in Linux Mono using Fast Colored Text Box

I am creating a small GUI in WinForms and am currently working on implementing a syntax highlighter. I found a library that runs great in windows and provides a dll for usage. However, the library seems to always crash in Linux. Here is the error I'm getting:
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at FastColoredTextBoxNS.FastColoredTextBox..ctor () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) FastColoredTextBoxNS.FastColoredTextBox:.ctor ()
at FDE.FGUI..ctor () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) FDE.FGUI:.ctor ()
at FDE.FGUI.Main () [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
at FastColoredTextBoxNS.FastColoredTextBox..ctor () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) FastColoredTextBoxNS.FastColoredTextBox:.ctor ()
at FDE.FGUI..ctor () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) FDE.FGUI:.ctor ()
at FDE.FGUI.Main () [0x00000] in <filename unknown>:0
From the error message, it seems that Mono isn't seeing the dll given the <filename unknown> error during the constructor. Admittedly, The library I'm using (FastColoredTextBox) does not pass MoMA as it has a fair amount of P/Invokes. However, some people seemed to say they were able to get it running by avoiding the conflicting methods.
Here's the clincher, though. I decided to try to run the GUI through WINE and completely bypass Mono. Since it ran fine it Windows, I thought this would fix the error. However, the exact same error message pops up in Wine. I even have a shared folder between Windows and my Ubuntu live machine. The same exact executable will run on perfect Windows, but crash with this error in Linux. At this point, after hours of researching, I'm stumped.
Is there a certain way a dll has to be loaded in Mono or does the error lie in Mono/Wine incompatibilities with WinForms?
I looked at the source to the library. Assuming I've found the right library, it's calling the Win32 API, which isn't going to work on stock Mono.
Running under Wine should work better, but Wine is only partially implementing the Win32 API.
You may need to find a cross-platform replacement.

C# Couldn't decode XML

I am having a problem where my C# program running in Mono on a Raspberry Pi with Arch Linux gives an error when I try to make it load a key from an XML string or file. It can encrypt and decrypt a message when I tell it to generated its own keys but if I were to take the exact same XML of the generated keys gotten from ToXmlString and give them to it through FromXmlString then it complains about "System.Security.Cryptography.CryptographyException: Couldn't decode XML...".
I should mention that providing any code is probably useless because the exact same code works perfectly when run on Windows or my Arch Linux desktop, the issue obviously has something to do with the ARM Mono implementation for the RPi which after a quick version check is said to be V2 (I have updated it just now) whereas my desktop Arch Linux has V4.
I would therefore like to know if anyone knows of a workaround for this or could report it as a bug to the Mono developers.
EDIT:
Here is the full console output:
Unhandled Exception: System.Security.Cryptography.CryptographicException: Couldn't decode XML ---> System.Security.Cryptography.CryptographicException: Private/public key mismatch
at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
--- End of inner exception stack trace ---
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
at PHPEncryptTest.RSA.EncryptData (System.String strData2Encrypt) [0x00000] in :0
at PHPEncryptTest.Program.Main (System.String[] args) [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Security.Cryptography.CryptographicException: Couldn't decode XML ---> System.Security.Cryptography.CryptographicException: Private/public key mismatch
at Mono.Security.Cryptography.RSAManaged.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters (RSAParameters parameters) [0x00000] in :0
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
--- End of inner exception stack trace ---
at System.Security.Cryptography.RSA.FromXmlString (System.String xmlString) [0x00000] in :0
at PHPEncryptTest.RSA.EncryptData (System.String strData2Encrypt) [0x00000] in :0
at PHPEncryptTest.Program.Main (System.String[] args) [0x00000] in :0
I have been running mono on RPI for a while now, but i have not gone into the security namespace, since mono best supported on linux and they are porting (lose words) the .Net framework to fit linux we can always expect some bugs, especially when namespaces as security,
check out: Mono System.Security.Cryptography.CryptographicException when running on Linux

Categories

Resources