J
Jason
I have created a dll from a C++ class using .Net and have imported it into my
C# applications (one webservice, one standalone app). It works fine for a
while, but will eventually fail to produce the error
"System.NullReferenceException: Object reference not set to an instance of an
object" when calling a method from the dll. In the case of the webservice,
after it fails once it continues to fail until I reboot. My searches have
been unsuccessful in finding a solution. I am using XP Pro with IIS 5.1 for
the webservice.
The only suggestion I have found through search is to check the permissions,
which I have done, but I could probably use some more detailed instructions
on how to do this.
Any suggestions on how I might fix this problem?
The code:
DLL call that produces the error:
IntPtr pMSG = MSG_Class.CreateMSGClass();
and also:
byte[] Message = new byte[MSG_Class.GetBufferSize(pMSG)];
MSG_Class.GetBuffer(pMSG , Message); // this fails occasionally
import:
DLL Import class:
[DllImport("MSG_1.dll")]
public static extern IntPtr CreateMSGClass ();
[DllImport("MSG_1.dll",CallingConvention=CallingConvention.ThisCall)]
public static extern void GetBuffer( IntPtr instance, byte [] bufferOut );
C++ (from which the dll was created):
CreateMSGClass:
return new MSGClass();
void MSG_Class::GetBuffer(char * BufferOut) {
memcpy(BufferOut, TheBuffer, sizeof(TheBuffer);
}
C# applications (one webservice, one standalone app). It works fine for a
while, but will eventually fail to produce the error
"System.NullReferenceException: Object reference not set to an instance of an
object" when calling a method from the dll. In the case of the webservice,
after it fails once it continues to fail until I reboot. My searches have
been unsuccessful in finding a solution. I am using XP Pro with IIS 5.1 for
the webservice.
The only suggestion I have found through search is to check the permissions,
which I have done, but I could probably use some more detailed instructions
on how to do this.
Any suggestions on how I might fix this problem?
The code:
DLL call that produces the error:
IntPtr pMSG = MSG_Class.CreateMSGClass();
and also:
byte[] Message = new byte[MSG_Class.GetBufferSize(pMSG)];
MSG_Class.GetBuffer(pMSG , Message); // this fails occasionally
import:
DLL Import class:
[DllImport("MSG_1.dll")]
public static extern IntPtr CreateMSGClass ();
[DllImport("MSG_1.dll",CallingConvention=CallingConvention.ThisCall)]
public static extern void GetBuffer( IntPtr instance, byte [] bufferOut );
C++ (from which the dll was created):
CreateMSGClass:
return new MSGClass();
void MSG_Class::GetBuffer(char * BufferOut) {
memcpy(BufferOut, TheBuffer, sizeof(TheBuffer);
}