Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid NullReferenceException if context is null #4727

Merged
merged 3 commits into from
Jul 13, 2020
Merged

Avoid NullReferenceException if context is null #4727

merged 3 commits into from
Jul 13, 2020

Conversation

1d0n7kn0w
Copy link
Contributor

No description provided.

@maliming
Copy link
Member

maliming commented Jul 13, 2020

hi @1d0n7kn0w
DataSeedContext will not be null by default. Can you explain?

@1d0n7kn0w
Copy link
Contributor Author

Hi @maliming
I created a new solution, then I deleted all the things related to multitenancy
So in the class "src/{name}.Domain/Data/{name}DbMigrationService.cs" and specifically in the private method "SeedDataAsync()" I made this change from "await _dataSeeder.SeedAsync(tenant?.Id);" to "await _dataSeeder.SeedAsync(null);"
At first, I didn't know why the DbMigrator was throwing a NullReferenceException, after investigation with null "Volo.Abp.Data.IDataSeeder.SeedAsync(DataSeedContext context)" is used, so to avoid this I had to use the parameterless one so it uses "Volo.Abp.Data.DataSeederExtensions.SeedAsync(this IDataSeeder seeder, Guid? tenantId = null)"

@maliming
Copy link
Member

hi

You can use this extension method instead of passing null.

public static Task SeedAsync(this IDataSeeder seeder, Guid? tenantId = null)

@1d0n7kn0w
Copy link
Contributor Author

yes that's what I did as I mentioned in my comment, but to simplify things for other developers, passing null or nothing should have the same result I guess

@maliming
Copy link
Member

Ok, can you also handle IdentityDataSeedContributor?

image

@1d0n7kn0w
Copy link
Contributor Author

Done, with pleasure 😄

@maliming maliming added this to the 3.1 milestone Jul 13, 2020
@maliming maliming merged commit b49684a into abpframework:dev Jul 13, 2020
@1d0n7kn0w 1d0n7kn0w deleted the patch-1 branch July 13, 2020 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants