muwpa

Exception when using AFAttribute.DataReference

Discussion created by muwpa on Mar 15, 2012
Latest reply on Mar 20, 2012 by mhamel

Hello v-campers ;)

 

I'm actually working on a PB-Addin that shows in a docking window a AFTreeView. The User can navigate through the TreeNodes to an AFAttribute. To visualize (Trend, Value, SQC,..) a chosen AFAttribute the user has to drag and drop it into the PB display.

 

In the ItemDrag-Event of the AFTree I build a string containing a visualisazion (e.g. Trend), and the Tag (which is represented by an AFAttribute). To get the Tag name of the AFAttribute I used the following function:

 

 

 
private string getSelectedAFAttribute(AFTreeNode aftn)
{
     string tag = string.Empty;
     try
     {
           AFAttribute afa = (AFAttribute)aftn.AFObject;
           tag = afa.DataReference.ToString();
     }
     catch (System.Runtime.InteropServices.COMException ex)
     {
           System.Diagnostics.Debug.WriteLine(ex.Message + " " + ex.StackTrace);
     }
     catch (System.Exception ex)
     {
           System.Diagnostics.Debug.WriteLine(ex.Message + " " + ex.StackTrace);
     }
            StringBuilder builder = new StringBuilder();
            // using StringBuilder to create my "visualization string"
            return builder;
}

 In the Connect class there is the other part of the drop-handling.The problem occurs in the line

 

 

 
tag = afa.DataReference.ToString();

In the VS2010 debug output window I get the following error:

 

"A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in OSIsoft.AF.Asset.DataReference.PIPoint.dll"

 

That's the reason for the second catch in the code I posted, but this exception is not catched by my catch-statement. Maybe anyone else has/had this problem too. Are there any suggestions to avoid this error?

 

 

 

Thanks in advance,

 

Chris

 

 

Outcomes