AnsweredAssumed Answered

Error message when try to get all attributes in DB have analysis

Question asked by Saken on Jul 11, 2017
Latest reply on Aug 7, 2017 by Saken

Hi,

I have following code to get all attributes in DB have analysis, see attachment code:

 

     static void Main(string[] args)
        {
            var piSystems = new PISystems();
            var piSystem = piSystems["pi_server_name"];
            piSystem.Connect();
            var db = piSystem.Databases["Machine Reliability"];
            var analysisOutputs = new List<AFAttribute>();
            AFNamedCollectionList<OSIsoft.AF.Analysis.AFAnalysis> search = OSIsoft.AF.Analysis.AFAnalysis.FindAnalyses(db, "*", AFSearchField.Name, AFSortField.Name, AFSortOrder.Ascending, Int32.MaxValue);

            foreach (var analysis in search)
            {
                var configuration = analysis.AnalysisRule.GetConfiguration();
                foreach (var output in configuration.ResolvedOutputs)

                {
                    analysisOutputs.Add((AFAttribute)output.Attribute);
                }
            }

            foreach (var attribute in analysisOutputs)
            {
                Console.WriteLine(attribute.Name);
            }
        }

 

 

And it retrieves data but stops with message, see attachment console output:

 

Area Availability Average

{ cut to reduce list }

Area Availability Average

Area Reliability Average

{ cut to reduce list }

Area Runtime Average

Area Trips Total Count

{ cut to reduce list }

Area Trips Total Count

 

 

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.

   at PI_project.Program.Main(String[] args) in c:\users\mskn\documents\visual studio 2017\Projects\PI project\PI project\Program.cs:line 36

Press any key to continue . . .

 

 

please advice what's wrong here.

 

Also how to get full path to element attributes in result?

 

 

thanks,

S

Outcomes