[Mono-bugs] [Bug 62394][Nor] New - DllImport broken under Linux

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 3 Aug 2004 23:12:10 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by michi@zeroc.com.

http://bugzilla.ximian.com/show_bug.cgi?id=62394

--- shadow/62394	2004-08-03 23:12:10.000000000 -0400
+++ shadow/62394.tmp.18060	2004-08-03 23:12:10.000000000 -0400
@@ -0,0 +1,68 @@
+Bug#: 62394
+Product: Mono: Runtime
+Version: unspecified
+OS: 
+OS Details: RedHat 8
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: michi@zeroc.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: DllImport broken under Linux
+
+The following code dies with a TypeInitializationException in the call to
+BZ2_bzlibVersion:
+
+    public class BasicStream
+    {
+        [DllImport("libbz2.dll")]
+        static extern String BZ2_bzlibVersion();
+
+        static BasicStream()
+        {
+            //
+            // Simple trick to find out whether libbz2 is installed:
+            // Call the BZ2_bzlibVersion() function in the library. If we get
+            // a DllImportException, the library is not available.
+            //
+            _bzlibInstalled = true;
+            try
+            {
+                BZ2_bzlibVersion();
+            }
+            catch(System.DllNotFoundException)
+            {
+                _bzlibInstalled = false;
+            }
+        }
+
+        // ...
+    }
+
+Here is the stack trace:
+
+Unhandled Exception: System.TypeInitializationException: An exception was
+thrown by the type initializer for IceInternal.BasicStream --->
+System.NullReferenceException: Object reference not set to an instance of
+an object
+in (unmanaged) (wrapper managed-to-native)
+System.Object:__icall_wrapper_g_free (intptr)
+in <0x00004> (wrapper managed-to-native)
+System.Object:__icall_wrapper_g_free (intptr)
+in <0x0003d> (wrapper managed-to-native)
+IceInternal.BasicStream:BZ2_bzlibVersion ()
+in [0x0001e] (at /home/michi/src/icecs/src/Ice/BasicStream.cs:49)
+IceInternal.BasicStream:.cctor ()
+
+The same code works fine under Windows with both .NET and Mono (whether I
+compile it there with Visual C# or mcs makes no difference).
+
+Cheers,
+
+Michi.