You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generic collections that have copy constructors (with IEnumerable<T> as parameter) are initialized with elements, when using ActivatorUtilities.CreateInstance/ActivatorUtilities.GetServiceOrCreateInstance.
The collection object is an empty instance of List, because ActivatorUtilities.CreateInstance uses the constructor public List()
Actual behavior
The collection object is an instance of List containing two elements: one instance of Test and one of Test2. Currently, ActivatorUtilities.CreateInstance is selecting the constructor public List(IEnumerable<T> collection).
Regression?
We found this issue while upgrading from .Net 6 to .Net 8
Known Workarounds
No response
Configuration
.Net SDK 8.0.403
Other information
In such cases, the parameterless constructor may be preferable - particularly for generic collections with copy constructors. Consider annotating the expected constructors with the ActivatorUtilitiesConstructorAttribute to ensure the correct constructor is chosen.
The ActivatorUtilities is being used in a serialization & deserialization context where many different types are involved, including system generic collections. We used to have a clean solution by using the it.
Description
Generic collections that have copy constructors (with
IEnumerable<T>
as parameter) are initialized with elements, when usingActivatorUtilities.CreateInstance
/ActivatorUtilities.GetServiceOrCreateInstance
.Reproduction Steps
Expected behavior
The
collection
object is an empty instance ofList
, becauseActivatorUtilities.CreateInstance
uses the constructorpublic List()
Actual behavior
The collection object is an instance of List containing two elements: one instance of
Test
and one ofTest2
. Currently,ActivatorUtilities.CreateInstance
is selecting the constructorpublic List(IEnumerable<T> collection)
.Regression?
We found this issue while upgrading from .Net 6 to .Net 8
Known Workarounds
No response
Configuration
.Net SDK 8.0.403
Other information
In such cases, the parameterless constructor may be preferable - particularly for generic collections with copy constructors. Consider annotating the expected constructors with the
ActivatorUtilitiesConstructorAttribute
to ensure the correct constructor is chosen.It should be related with:
The text was updated successfully, but these errors were encountered: