Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

NullReferenceException in Console Application with the method SubscribeMultipleItems.

More
19 Nov 2012 15:58 #1100 by support
Hello,
I am not sure if I understand your question, but I will try...
According to our documentation, you should test eventArgs.Exception before accessing eventArgs.Vtq. If eventArgs.Exception is non-null, then it contains information about the problem, and eventArgs.Vtq is null, so you should not dereference it.
When eventArgs.Exception is null, then it is guaranteed that eventArgs.Vtq. is not null. But, eventArgs.Vtq.Value may still be null, if the quality (eventArgs.Vtq.Quality) is bad, or even if it is good but the OPC server has sent a null (VT_EMPTY) value.
Best regards

Please Log in or Create an account to join the conversation.

More
16 Nov 2012 18:31 #1098 by jeancg
Hello.

You're right, I had done in console windows just to demonstrate what I was doing, the application will be written in windows forms and some improvements in the method that writes to the database.

I would like an opinion about how to mitigate this type of behavior so that there is more to excetion and stop the application when initializing.

I put a check as you suggested, he stopped the NullReferenceException error occur, but am not sure if this solves the problem.

if (eventArgs.Vtq != null && eventArgs.Vtq.Value != null)

Thank you.

Please Log in or Create an account to join the conversation.

More
09 Nov 2012 09:06 #1092 by support
Hello,
I cannot give definitive answer, because your post does not state the details about the exception (call stack etc.), or which object is null but you think it should not be.
But I have looked at your code and made some general observations, though:

The Main method just subscribes, and the method then immediately exits. This does not look right - I am sure you want to stay subscribed for some time. It could be shutting down the program while still subscribed, which can lead to problems. You need to have some logic regarding how long you want the program to stay subscribed, and only exit the Main method when you are done (and, proper clean up, by unsubscribing, is highly recommended).
OPC Servers can send notifications with Bad quality at any time, due to conditions in the underlying system, or (with some servers) even initially, before the first data is available. When this happens, the Value portion of the DAVtq object (the Vtq property of the notification event arguments) does not contain any valid data, and is therefore null. But your code is doing eventArgs.Vtq.Value.ToString(), without checking it first. This is not right.

I hope this helps.

Please Log in or Create an account to join the conversation.

More
08 Nov 2012 17:26 #1091 by jeancg
Hello again.

I have a windows console application in order to monitor and record opc my items in a database. I'm using SubscribeMultipleItems and a method to manipulate the inclusion of the data in two tables.

This application aims to monitor tags opc alarms that are on my system, all tags are Boolean and are considered alarms when your state is in true.

When I run the application I get an error of NullReferenceException, I close the application with error and restart it again and it works normally.

Using Visual Studio debug this happens when the property Vtq my eventArgs this null and an opc tag this with bad quality, but when I test this tag using the Demo Application quality good returns in the same tag.

I am sending the class attached to the code.

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.047 seconds