unsafe C# with C-library call; object reference not set to an instance

  • Thread starter Thread starter Francois Vanderseypen
  • Start date Start date
F

Francois Vanderseypen

I have a C-library to access a Tivoli LDAP directory. Thanks to this
newsgroup I managed to find the correct DllImport (thanks everybody!),
which is:


[DllImport("SIT_UML.dll", EntryPoint="SIT_Registry_Initialise")]public
static extern int InitializeRegistry(ref UIntPtr
LDAPSession,[MarshalAs(UnmanagedType.LPStr)]string
HostPort,[MarshalAs(UnmanagedType.LPStr)]string
AdminUserID,[MarshalAs(UnmanagedType.LPStr)]string AdminPassword);

The LDAPSession is created in my call and I can see that the variable
has a value. In the LDAP browser I can also see a connection is
created, however when I try to pass this to a call as a ref argument
I get an error stating "Object reference not set to an instance of an
object."

The signature in the C-lib is:

[DllImport("SIT_UML.dll", EntryPoint="SIT_TAM_User_Create")]public
static extern int CreateUser(ref UIntPtr LDAPSession,string
TAMID,string UserID,string UserPassword,int Complete);


which I call via

CreateUser(ref LDAPSession,"user","userDN","123",1);

It seems as if the memory block is created but does not contain the
right information? Do I have to cast?

Thanks for helping me out!
 
Francois,

I don't think a cast is necessary. This might be a foolish question,
but what is the value of the LDAPSession that you are passing. If it is
zero, then this is the cause. Otherwise, there is something in the
structure/interface/class that is represented by LDAPSession that might be
zero which is raising the error and bubbling up.

Hope this helps.
 
Back
Top