InvalidOperationException When Calling CreatePIPoint

Hi there,

 

I'm trying to call CreatePIPoint of a PIServer object with attributeValues set to a string-object dictionary of 5 attributes. The attributes are as follows:

 

  • tag: TEST_TAG_NEW
  • pointtype: Float32
  • compmax: 28800
  • ptsecurity: piadmins: A(r,w)
  • datasecurity: piadmins: A(r)

 

Note that the pointName parameter of CreatePIPoint is the same as the "tag" attribute (i.e., TEST_TAG_NEW).

 

When the call is made, an InvalidOperationException is thrown with the following message: "Unexpected behavior. Expected Stream object count of 1. Actual object count (0) was returned." However, the tag is created on the PI server with all attributes in attributeValues being set correctly, even though the exception has been thrown.

 

I had tried to remove the "tag" attribute, but I'm still getting the same exception and message.

 

Can anyone help with what could be the cause of this exception, please?

 

Thank you.

 

- Riyadh

Parents
  • First, other than a lack of the actual code you are using, the question is both phrased and tagged very well.

     

    Second, while I cannot explain the exception, I am concerned that you have not specified enough point attributes from a viewpoint of best practices and not neccessarily how to get past the exception. For instance, I would like to see at the very least the PointClass and PointSource defined.

     

    Help link for PICommonPointAttributes

     

    What I find helpful for myself is to open up SMT, go to Point Builder, and go through the motions of creating the tag there. I then write down all the settings that I explicitly edited. Then back in my AF SDK code, I add those same settings to the dictionary used by CreatePIPoint.

     

  • Hi Rick,

     

    Thank you for your reply! As for the code, it is more or less as follows:

    PIServer piServer = PIServer.FindPIServer(/* Server name omitted */);
    /* Null check omitted */
    
    piServer.Connect();
    
    string pointName = "TEST_TAG_NEW";
    
    Dictionary<string, object> attribs = new Dictionary<string, object>();
    attribs.Add(PICommonPointAttributes.Tag, pointName);
    attribs.Add(PICommonPointAttributes.PointType, "Float32");
    attribs.Add(PICommonPointAttributes.CompressionMaximum, 28800);
    attribs.Add(PICommonPointAttributes.PointSecurity, "piadmins: A(r,w)");
    attribs.Add(PICommonPointAttributes.DataSecurity, "piadmins: A(r)");
    
    piServer.CreatePIPoint(pointName, attribs);  // Throws InvalidOperationException
    
    piServer.Disconnect();

    I tried appending the following two lines to the sequence of attribs.Add statements, but the exception is still thrown:

    attribs.Add(PICommonPointAttributes.PointClassName, "classic");
    attribs.Add(PICommonPointAttributes.PointSource, /* Point source omitted */);

    In our case, we want the attributes not in the dictionary to be set to the default value as defined on the PI system (as opposed to writing extra lines of code to cover those attributes). Would you say it is best practice to always set them in such case?

     

    - Riyadh

  • Hi Asle,

     

    Thanks for the suggestion! I managed to find the attribute causing the exception to be thrown as a result: ptsecurity.

     

    After more debugging, I found that the exception was thrown because our application is running on a test environment by a test AD account whose mapped PI identity is not a member of piadmins.

    Thus, the app should not be able to modify (or even be aware of) the newly-created tag (duh Sweat smile).

     

    When adding the test account identity to ptsecurity, the exception is no longer thrown:

    attribs.Add(
        PICommonPointAttributes.PointSecurity,
        $"piadmins: A(r,w) | {/* Test account identity omitted */}: A(r,w)");  // No exceptions thrown (hooray!)

     

    Once again, thank you so much for the tip!

     

    - Riyadh

Reply
  • Hi Asle,

     

    Thanks for the suggestion! I managed to find the attribute causing the exception to be thrown as a result: ptsecurity.

     

    After more debugging, I found that the exception was thrown because our application is running on a test environment by a test AD account whose mapped PI identity is not a member of piadmins.

    Thus, the app should not be able to modify (or even be aware of) the newly-created tag (duh Sweat smile).

     

    When adding the test account identity to ptsecurity, the exception is no longer thrown:

    attribs.Add(
        PICommonPointAttributes.PointSecurity,
        $"piadmins: A(r,w) | {/* Test account identity omitted */}: A(r,w)");  // No exceptions thrown (hooray!)

     

    Once again, thank you so much for the tip!

     

    - Riyadh

Children
No Data