2

I would like to expose this problem to the stack overflow community to see if anyone can give me some input on how to fix this problem. The main objective here is to use Mono's mkbundle tool in order to create a self contained binary that will be executed in an embedded systems environment with no mono (or related libraries) installed.

Project code example

The app that I am using is a small example that simply loads a window. On this image you can see the dependendies, which I have setup to include local copies for all of them. This means that both the .dlls of these references and their dll map configs will both be present in the debug folder along with the executable. It should be also noted that if I dont include local copies of the dependencies the the mkbundle command will fail.

So I try to execute mkbundle with this command:

mkbundle -o App App..exe --simple --deps --machine-config "/usr/etc/etc/mono/4.5/machine.config" --config "/etc/mono/config"

After which I am presented with this promissing report of linked assemblies and libraries:

   Assembly: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/Graphics.exe
 Assembly: /usr/lib/mono/4.5/mscorlib.dll
 Assembly: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/gtk-sharp.dll
   Config: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/gtk-sharp.dll.config
 Assembly: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/glib-sharp.dll
   Config: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/glib-sharp.dll.config
 Assembly: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/System.dll
 Assembly: /usr/lib/mono/4.5/System.Configuration.dll
 Assembly: /usr/lib/mono/4.5/System.Xml.dll
 Assembly: /usr/lib/mono/4.5/System.Security.dll
 Assembly: /usr/lib/mono/4.5/System.Core.dll
 Assembly: /usr/lib/mono/4.5/System.Numerics.dll
 Assembly: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/gdk-sharp.dll
   Config: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/gdk-sharp.dll.config
 Assembly: /usr/lib/mono/4.5/Mono.Cairo.dll
 Assembly: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/pango-sharp.dll
   Config: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/pango-sharp.dll.config
 Assembly: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/atk-sharp.dll
   Config: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/atk-sharp.dll.config
 Assembly: /home/tansvanio/Projects/Graphics/Graphics/bin/Debug/Mono.Posix.dll
 Assembly: /usr/lib/mono/4.5/I18N.West.dll
 Assembly: /usr/lib/mono/4.5/I18N.dll

systemconfig: /etc/mono/config machineconfig: /usr/etc/mono/4.5/machine.config

As we can see, not only the DLLS from the original mono map in /etc/mono/config where linked, but also the ones needed by our gtk dependencies.

After this I will try to run the generated binary.

./App

And the app crashes and gives me this error:

Unhandled Exception:
System.TypeLoadException: Could not set up parent class, due to: Could not 
set up parent class, due to: Could not set up parent class, due to: Could 
not set up parent class, due to: Could not set up parent class, due to: 
Could not set up parent class, due to: Could not set up parent class, due 
to: Could not load type of field 'GLib.Object:before_handlers' (15) due to: 
Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089' or one of its dependencies. assembly:glib- 
sharp.dll type:Object member:(null) assembly:glib-sharp.dll 
type:InitiallyUnowned member:(null) assembly:gtk-sharp.dll type:Object 
member:(null) assembly:gtk-sharp.dll type:Widget member:(null) assembly:gtk- 
sharp.dll type:Container member:(null) assembly:gtk-sharp.dll type:Bin 
member:(null) assembly:gtk-sharp.dll type:Window member:(null)
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not set 
up 
parent class, due to: Could not set up parent class, due to: Could not set up parent class, due to: Could not set up parent class, due to: Could not set up parent class, due to: Could not set up parent class, due to: Could not set up parent class, due to: Could not load type of field 'GLib.Object:before_handlers' (15) due to: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. assembly:glib-sharp.dll type:Object member:(null) assembly:glib-sharp.dll type:InitiallyUnowned member:(null) assembly:gtk-sharp.dll type:Object member:(null) assembly:gtk-sharp.dll type:Widget member:(null) assembly:gtk-sharp.dll type:Container member:(null) assembly:gtk-sharp.dll type:Bin member:(null) assembly:gtk-sharp.dll type:Window member:(null)

This is really frustrating because I have tried this process several times and confirmed that it is working for smaller apps with no references. I wonder if anyone has encountered this problem before and knows how to fix this or do it properly if I am failing somehow.

Best regards, Ricardo

0 Answers0