Link to home
Start Free TrialLog in
Avatar of jdancel
jdancelFlag for United States of America

asked on

Object Reference not set to an instance of an object error?!

Does anyone have a sample of how to use the PGP Com Wrapper nsdpgp3.dll in vb.net 2003?  I keep getting the following error when I try to run the decryption..."Object reference not set to an instance of an object" and yet I have this statement in my event
Dim df As Nsdpgp3Lib.PGP = New Nsdpgp3Lib.PGP.  Thank you in advance to anyone that responds to this question.
Avatar of AerosSaga
AerosSaga

Try creating a new instance so you can see what input values it is expecting like this:

Dim df As New Nsdpgp3Lib.PGP(

after you hit that last character it should show you what type of inputs it is expecting

Also, have you added a reference to that dll in your project?

Regards,

Aeros
since the "New" keyword calls the constructor, which is a method, try calling it like it is a method (with the parens).

dim df as Nsdpgp3Lib.PGP = new Nsdpgp3Lib.PGP()

Avatar of jdancel

ASKER

There is a reference to the dll in my project and when I try add the parentheses to the end of the dim statement, they disappear.  It does not appear that the pgp object is looking for any inputs.  

What is interesting is that "intellisense" does see the various properties and methods that are part of this library when I type "df." after my dim statement, I get several options i.e. keytype, hash, class, server, etc.  Even though the project seems to "see" the pgp object because of the intellisense response, I still get the same error..."Object reference not set to an instance of an object".

The statement that I am trying to execute is pretty straightforward.....as follows:

df.decryptfile(pubkey, privkey, infile, outfile, passphrase)  

All of the inputs are strings.

I get the error when I try to step through this statement.  The syntax to the statement is the same syntax that intellisense prompts for and is the same syntax in the vb6 samples provided.  The sample vb6 code does not require a return variable so I assumed that neither would vb.net.  Out of frustration I even tried to precede the statement with a return variable, thinking that maybe that was the problem, the build came back with "Expression does not return a value".

Thanks again for your input.
send me a link to the documentation and where I can download the COM library...
Avatar of jdancel

ASKER

This library is a COM wrapper to the PGP program.  The COM wrapper can be downloaded from the following link:

http://community.wow.net/grt/nsdpgp.html

You must have PGP installed also.  I am using the most recent version 8.1.  It can be downloaded from the following link:

http://www.pgp.com/products/freeware.html

Thanks
Is the object you are passing INTO the decryption routine defined?  Your "df" variable is most likely not the culprit, but more likely something the decription algorithm is trying to reference.
One thing I noticed after installing PGP and playing with the API is that since it is a COM library, after you add a reference to the library, a wrapper is automatically generated by VS IDE.

When you instantiate the class, use the wrapper constructor, namely,

Dim df As New PGPClass
Avatar of jdancel

ASKER

Ptakja...

All the objects that I am passing into the decryption routine are defined.  They are all string objects that have been defined.  I have a breakpoint set on the decryption statement and as I check the string objects before the statement executes...all the string objects are populated with the correct values.

gregasm...

I tried to dimension the wrapper as follows:

Dim df as New Nsdpgplib.pgpclass  (the pgpclass shows up in intellisense)

Unfortunately, the problem still persists.  
This is strange. I have worked with COM wrappers before, and they don't need much more than what you have already done, by way of instantiation.

Create a new VB6 project and try to instantiate the class. Perhaps if you get an error message there, it may be helpful to find out what is going on.

If it works there, then at least we know that it works that far.

I am suspecting that perhaps the PGP COM component is not registered correctly. I am using PGP 7.1 and it is working fabulously...
Avatar of jdancel

ASKER

gregasm

Were you able to get the COM Wrapper to work in vb.net 2003?  If so, what did the code look like?
I could not get it to work, but the error message I get when trying to instantiate the COM class from the Interop wrapper is this:

COM object with CLSID {D1F6EAFC-F915-408D-8D07-DF80935D874E} is either not valid or not registered.

I am thinking that maybe the PGP8.1 installation program I used was not the one designed to be used with the API you pointed to in the link above.

I am not sure which API and pgp version go together. Can you help me get those two correct? Then I might be able to move ahead.
did you register it with IIS using the regsvr32.exe utility located in \WINNT\system32?

Regards,

Aeros
Avatar of jdancel

ASKER

gregasm

vb.net should see the object if you register it as suggested by AeroSaga.  vb.net sees my installation of the nsdpgp3.dll but it just doesn't seem to want to "play" nice with my pgp8.1.
sorry it has taken me so long to get back to you... i can duplicate your scenario exactly now after I registered the COM library. I'll let you know what I find out.
Add an imports statement

Imports Microsoft.VisualBasic

And then this code will instantiate the object:

Dim df As Nsdpgp3Lib.PGP
df = CreateObject("NSDPGP3Lib.PGP")

Avatar of jdancel

ASKER

Does this mean that you were able to get your code to decrypt?  Because I still get the same error, even with your object instantiation?!  I might be doing something else wrong also.  If you have the COM Wrapper decrypting, could you send me a sample of the code so that I can see what you're doing?

Thanks again for your persistence and your insight.
You know what, I was testing the library to see if it was instantiated by calling a method, not the decrypt method.

I called the WipeFile method, and that apparently works, whether the class is instantiated the first way, or the other way I suggested.

So, without further (and very hardcore, lower level) debugging, this issue is not yet resolved.

I suggest using PGP version 7.x... I use that version in my production applications and it works without a hitch.
Avatar of jdancel

ASKER

Any suggestions where I can find a copy of PGP version 7.x?
http://www.mcafeesecurity.com/us/downloads/evals/default.asp

You can download a trial version of McAfee E-Business Server for Windows 7.1.1 there.

http://www.networkassociates.com/common/media/pgp/support/pgp/e-biz/ebiz71/readme71.txt

Here is the readme file for the PGP E-Business Server v.7.1.

Avatar of jdancel

ASKER

The PGP 7.1 version is not compatible with Windows XP or Windows Server 2003.  I am forced to use PGP 8.1 but again the nsdpgp3.dll does not seem to be compatible with PGP 8.1.  Any other suggestions?
It is compatible. If you add a reference, then the VS IDE will generate a wrapper for the COM library. It is not natively compatible, is what I think you mean. .NET can generate wrappers, and also with P-Invoke, can even invoke methods from classes that are not COM compatible.

Another route is to shell out to the command line and then run the commands from there.
Avatar of jdancel

ASKER

I had thought of this but if I shell out to the command line, how do I verify the success of the execution of a function?  I am required to provide status updates in the event log.  If I do not receive a return value from a function, then how can I verify that the execution of the command was successful?  Thank you for any suggestions.
ASKER CERTIFIED SOLUTION
Avatar of gregasm
gregasm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial