bchavez / Bogus

:card_index: A simple fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js.
Other
8.62k stars 491 forks source link

Null Reference Exception on .Generate() #464

Closed WbryantCampbell closed 1 year ago

WbryantCampbell commented 1 year ago

Version Information

Software Version(s)
Bogus NuGet Package 34.0.2
.NET Core? no
.NET Full Framework? yes .NET Standard 2.1
Windows OS? yes
Linux OS? no
Visual Studio? yes

What locale are you using with Bogus?

en-us

What is the expected behavior?

I would love to see my static class finish initialization.

What is the actual behavior?

The process runs all the way MixtureFaker.Generate() whe

Please provide a stack trace.

at Bogus.Extensions.ExtensionsForPropertyInfo.<>c__DisplayClass2_02.b0(T instance, Object value) at Bogus.Faker1.PopulateProperty(T instance, PopulateAction1 action) at Bogus.Faker1.PopulateInternal(T instance, String[] ruleSets) at Bogus.Faker1.Generate(String ruleSets) at Verisk3E.Notify.Entity.SeededData.NotifyFakeData.<>cDisplayClass80_0.b__161(Faker f, ProductRecord b) in C:_git\v3e-notify\Verisk3E.Notify.Web\src\Verisk3E.Notify.Entity\SeededData\NotifyFakeData.cs:line 230`

Any possible solutions?

I could maybe switch to faker facade? I would really like not to redo all of my work up to this point though.

How do you reproduce the issue?

Running this code in my file.

Do you have a unit test that can demonstrate the bug?

No just the static file failing to create my seed data.

Can you identify the location in Bogus' source code where the problem exists?

No

If the bug is confirmed, would you be willing to submit a PR?

Yes or No?

If there's anything I can do to help, I 'd be glad to help.

NotifyFakeData.txt

karthitect commented 1 year ago

You might want to double check that all of the fields that you're setting to null with a non-zero probability are nullable. For instance:

.RuleFor(m => m.Country, f => f.Random.Int(0, 1000).OrNull(f, .75f))

Make sure that the Country field is nullable. Along with any other rules you're using OrNull on.

bchavez commented 1 year ago

Hi @WbryantCampbell, thank you for the bug report and source code. Unfortunately, I can't compile the example you provided. You'll need to send us a complete example that runs and compiles in LinqPad that demonstrates the problem if you want more help: https://www.linqpad.net

Feel free to re-open the GH issue if you can provide more information.

Thanks, Brian