testfx icon indicating copy to clipboard operation
testfx copied to clipboard

Data contract serialization for System.Type

Open Youssef1313 opened this issue 5 months ago • 1 comments

Today, System.Type isn't serializable via data contract serialization. Thus, any parameterized tests making use of System.Type will be forced to be folded. It will throw this exception:

System.Runtime.Serialization.InvalidDataContractException: 'Type 'System.RuntimeType' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.'

We catch the exception in TryUnfoldITestDataSources and then we don't "unfold" during discovery.

This is originally reported in https://developercommunity.visualstudio.com/t/C-TestExplorer-does-not-show-children-f/10936786

Youssef1313 avatar Jul 14 '25 17:07 Youssef1313

A better solution here is to avoid serialization altogether and solely rely on TestCaseIndex.

Youssef1313 avatar Nov 12 '25 05:11 Youssef1313