question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

Starting 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:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nickdodd79commented, Sep 26, 2019

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.

0reactions
j-fritschcommented, Oct 2, 2019

All my tests are passing again. Thanks again, @nickdodd79, I appreciate the quick responses!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found