Page 1 of 1

Casting Collection<>

Posted: Fri Dec 19, 2025 10:59 am
by admin@secsol.co.uk
I have some code in a function like this :

Code: Select all

	System.Collections.ObjectModel.Collection<Cypher1.FormField> FieldList = SelectedForm.FieldList as System.Collections.ObjectModel.Collection<Cypher1.FormField>;

  	foreach(Cypher1.FormField F in FieldList)
  	{
  	...... process data here ....
  	}
The SelectedForm.Field List is a Collection<FormField>

But this throws the error :

The error of compilation
The error of compilation is found in the 'Report' report:
Cannot convert type 'Reports.Report.SelectedFormBusinessObject.FieldListBusinessObject' to 'System.Collections.ObjectModel.Collection<Cypher1.FormField>' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion

What am I doing wrong?

Re: Casting Collection<>

Posted: Fri Dec 19, 2025 12:49 pm
by Lech Kulikowski
Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.

Re: Casting Collection<>

Posted: Fri Dec 19, 2025 2:32 pm
by admin@secsol.co.uk
I have attached the report

Re: Casting Collection<>

Posted: Fri Dec 19, 2025 3:35 pm
by admin@secsol.co.uk
I have managed to get this to work.

I had to change this

Code: Select all

System.Collections.ObjectModel.Collection<Cypher1.FormField> FieldList = SelectedForm.FieldList as System.Collections.ObjectModel.Collection<Cypher1.FormField>;
by adding the code .Current to the end of SelectedForm.FieldList like this :

Code: Select all

System.Collections.ObjectModel.Collection<Cypher1.FormField> FieldList = SelectedForm.FieldList.Current as System.Collections.ObjectModel.Collection<Cypher1.FormField>;

Re: Casting Collection<>

Posted: Mon Dec 22, 2025 12:07 pm
by Lech Kulikowski
Hello,

Thank you for the information.