Object of type 'System.Collections.Generic.List`1[System.String]' cannot be converted to type 'System.Collections.Generic.ISet`1[System.String]'.
See original GitHub issueStarting in v2.7.0, I’m getting a list conversion error when setting an ISet property with a HashSet populated via an IList within a rule. This is not happening in v2.6.0.
public class MyClass
{
public ISet<string> MySet { get; set; }
}
var faker = new AutoFaker<MyClass>()
.RuleFor(o => o.MySet, f => new HashSet<string>(f.Make(3, () => f.Lorem.Word())));
var fakes = faker.Generate();
The generation throws the conversion error.
System.ArgumentException:
at at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
at at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
at at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
at at AutoBogus.AutoMember.<>c__DisplayClass0_0.<.ctor>b__1(Object obj, Object value)
at at AutoBogus.AutoBinder.PopulateInstance[TType](Object instance, AutoGenerateContext context, IEnumerable`1 members)
at at AutoBogus.Generators.TypeGenerator`1.AutoBogus.IAutoGenerator.Generate(AutoGenerateContext context)
at at AutoBogus.AutoFaker`1.<>c__DisplayClass30_0.<PrepareCreate>b__0(Faker faker)
at at Bogus.Faker`1.Generate(String ruleSets)
at at AutoBogus.AutoFaker`1.Generate(String ruleSets)
at ConsoleApp1.Program.Main(String[] args) in /ConsoleApp1/ConsoleApp1/Program.cs:19
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Cannot convert object of type 'System.String' to ...
c# - Cannot convert object of type 'System. String' to type 'System. Collections. Generic.
Read more >Liquid error: Object of type 'System.Collections.Generic.List`1 ...
it to the type property as a string(using double quotes). And this is what the error says - that it cannot convert list...
Read more >Cannot implicitly convert type 'System.Collections.Generic. ...
I am facing following error Cannot implicitly convert type 'System.Collections.Generic.List<ERP_APP.Models.BigbaleView>' to 'System.
Read more >Convert System.Collections.Generic.List`1 ...
convert type System.Collections.Generic.ICollection<System.SystemException> to string. Now I assign as below. Email = mailBody.
Read more >Cannot implicitly convert type 'System.Collections.IList' to ' ...
Cannot implicitly convert type 'System.Collections.IList' to 'System.Collections.Generic.List. This is my first attempt at generics and I ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi.
The fact that the property is writable should mean you shouldn’t go down that generation path. I will take a look and push out a fix.
Nick.
All my tests are passing again. Thanks again, @nickdodd79, I appreciate the quick responses!