[Mono-list] Problem using p/invoke on mono 1.0.1
DI Mag. Rainer Burgstaller
rainer.burgstaller@web.de
Mon, 23 Aug 2004 08:20:36 +0200
Hi
First of all here is my configuration
Debian testing (quite up to date)
Mono-1.0.1 (got the mono-1.0.1.tar.gz)
I am trying to use libcrypt.so.2.3.2 with c#. This code has been working
for quite a while but stopped to work now.
here is a little sample program I wrote
<snip>
using System;
using System.Text;
using System.Security.Cryptography;
using System.Web.Security;
using System.Runtime.InteropServices;
namespace CryptTest
{
class CryptTest
{
[DllImport ("crypt", EntryPoint="crypt", SetLastError=true)]
private static extern string UnixCrypt(string text, string salt);
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("have {0} args",args.Length);
string arg = args[0];
Console.WriteLine("UnixEncrypting {0} :
{1}",arg,UnixCrypt(arg,arg));
}
}
}
</snip>
When I try to run this with
mono encrypt.exe rainer
I get a NullReference Exception. I am a bit lost here since this code has
been working beautifully for months. Either my debian upgraded its
libcrypt version (which could easily be true) or upgrading to mono-1.0.1
introduced the problem (which is less likely since I remember having the
same issue on mono-1.0).
Here is a snipped of the trace
.. . ENTER: (wrapper managed-to-native) PerfTest.PerfTest:UnixCrypt
(string,string)([STRING:0x80f8fc0:rainer], [STRING:0x80f8fc0:rainer], )
.. . . ENTER: (wrapper managed-to-native)
System.Object:__icall_wrapper_mono_string_to_utf8
(object)([STRING:0x80f8fc0:rainer], )
.. . . LEAVE: (wrapper managed-to-native)
System.Object:__icall_wrapper_mono_string_to_utf8 (object)result=135946400
.. . . ENTER: (wrapper managed-to-native)
System.Object:__icall_wrapper_mono_string_to_utf8
(object)([STRING:0x80f8fc0:rainer], )
.. . . LEAVE: (wrapper managed-to-native)
System.Object:__icall_wrapper_mono_string_to_utf8 (object)result=135941976
.. . . ENTER: (wrapper managed-to-native)
System.Object:__icall_wrapper_mono_string_new_wrapper (intptr)(0x41350540,
)
.. . . LEAVE: (wrapper managed-to-native)
System.Object:__icall_wrapper_mono_string_new_wrapper
(intptr)[System.String:0x80ef988]
.. . . ENTER: (wrapper managed-to-native)
System.Object:__icall_wrapper_g_free (intptr)(0x41350540, )
.. . . . ENTER: (wrapper runtime-invoke) System.Object:runtime_invoke_void
(object,intptr,intptr,intptr)([System.NullReferenceException:0x80f07b0],
(nil), (nil
), 0x413583d8, )
.. . . . . ENTER: System.NullReferenceException:.ctor
()(this:0x80f07b0[System.NullReferenceException encrypt.exe], )
.. . . . . . ENTER: Locale:GetText (string)([STRING:0x80f3c78:A null value
was found where an object instance was required.], )
.. . . . . . LEAVE: Locale:GetText (string)[STRING:0x80f3c78:A null value
was found where an object instance was required.]
.. . . . . LEAVE: System.NullReferenceException:.ctor ()
.. . . . LEAVE: (wrapper runtime-invoke) System.Object:runtime_invoke_void
(object,intptr,intptr,intptr)[OBJECT:(nil)]
EXCEPTION handling: NullReferenceException
I checked /usr/include/crypt.h again to make sure that there is not a new
version with different headers. But the function is still here
here is a snip of crypt.h
<snip>
/* Encrypt at most 8 characters from KEY using salt to perturb DES. */
extern char *crypt (__const char *__key, __const char *__salt) __THROW;
</snip>
so to me everything looks still fine but still it does not work.
Can anyone help?