0
votes

I wrote a method to submit an error-report via HTTP POST. I run OSX-Lion and MonoDevelop. The code works when the application is called from MonoDevelop. When I run the .app it throws an exception:

System.TypeInitializationException: An exception was thrown by the type initializer for System.Net.WebRequest ---> System.DllNotFoundException: libc.dylib
  at (wrapper managed-to-native) System.Platform:uname (intptr)
  at System.Platform.get_IsMacOS () [0x00000] in <filename unknown>:0 
  at System.Net.WebRequest..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at ch.fangorn.LIF.Access.SubmitCrash.Submit (Int32 projectId) [0x00000] in <filename unknown>:0 

At the moment I call the Submit method directly not via a catch. Since it works when a debugger is attached I'm stranded. What I so far tried:

  1. Build a mono application bundle (Create mac installer)
  2. Build everything with Platform target x86
  3. The beta version of Mono and MonoDevelop

The code that IMO causes the crash.

HttpWebRequest hwr = WebRequest.Create(turi) as HttpWebRequest;
string authInfo = user + ":" + password;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
hwr.Headers["Authorization"] = "Basic " + authInfo;

hwr.Method = "POST";
hwr.ContentType = "text/xml";
hwr.ContentLength = encData.Length;

Stream send = hwr.GetRequestStream();
send.Write(encData, 0, encData.Length);
send.Close();
hwr.GetResponse();

MonoDevelop: 2.8.5
Mono: 2.10.8

1
Have you tried looking at your references? I have had the necessity to remove and readd references to System.Web and others a few times in MonoDevelop, although older versions, with the same strange error mode.Eugen Rieck
I built a reduced sample with min references. Now I got a better error message: System.DllNotFoundException: libc.dylibGanwell
Ah, that's much better. Please try to update all dylib caches - I am not an OSX guy, but I had similar problems when building Gtk#/Mono apps on recently updated systems.Eugen Rieck
I found the problem: the wrapper script overrides the DYLD_FALLBACK_LIBRARY_PATH under the assumption that DYLD_FALLBACK_LIBRARY_PATH is set. But it seems that an empty DYLD_FALLBACK_LIBRARY_PATH means to use the default. So it removes the default and any possibility to find libc. I changed that line to include the documented default. Do you think that is a good solution?Ganwell
Yes, if you include it as the last itemEugen Rieck

1 Answers

0
votes

Symptom: System libraries not found (System.DllNotFoundException: libc.dylib) when a mono created .app is started outside of MonoDevelop.

In the wrapper-script created by mono develop: MyApp.app/Contents/MacOS/MyApp DYLD_FALLBACK_LIBRARY_PATH is set without including default. Since an empty DYLD_FALLBACK_LIBRARY_PATH means the default this will remove default. System libraries cannot be found.

In my opition the line should be:

export DYLD_FALLBACK_LIBRARY_PATH="$MONO_FRAMEWORK_PATH/lib:$DYLD_FALLBACK_LIBRARY_PATH:$(HOME)/lib:/usr/local/lib:/lib:/usr/lib"

Or a check if DYLD_FALLBACK_LIBRARY_PATH is empty would be even better.

I filed a bug-report: http://bugzilla.xamarin.com/show_bug.cgi?id=2727