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
{{ message }}
Repository navigation
Enable nullability in migrations and model snapshots #18950
I am generating migrations files for EF core with the new nullable reference types analysis turned on for an ASP.NET core app (3.0).
The migration file generated has several "new object[]" declarations that VS is flagging for CS8625 warnings (screenshot included).
Is there a work-around or change coming so that we don't have to do a global suppression. I want the nullable reference analysis, but just not for these migration files.
Reacted by Timo van Zijll Langhout, Danko Durbić, Grigory Zhadko, Maksym Koshovyi, Ross Lovas, Bastiaan Linders, JeroenMX, Hubert Rybak, Andrej Križan, Eli-Black-Work and 1 more
I did read somewhere that the NamespaceAndDescendants scope was broken in VS 16.7, and that it would be fixed in 16.8. I'm now on 16.8.2, but the suppression is not helping.
I think that by global suppression, it was meant that you don't activate the NRT feature at the project level (i.e. <Nullable>disabled</Nullable>). You can place your migrations in a separate project to keep nullability enabled in your actual code, if you want.
Another option is to place a #nullable disable at the top of each migration file.
@roji I'm pretty sure global suppressions is generally the term for what I mentioned above, so I assume that's what @TorreyGarland meant. I can't see why it's not working, though.
Disabling nullable for the entire project is too impactful, unfortunately. Adding #nullable disable at the top of each migration file would work, as would disabling the warnings from those locations.
I'm still hoping for a solution that makes the problem go away, instead of requiring each developer to remember for each new migration. We have "treat warnings as errors" enabled in the DevOps pipeline, to prevent the solution from becoming riddled with warnings... so it's quite a nuisance. 😛
You're right - global suppressions should indeed also work, I'm not sure why the above doesn't. I also agree we should provide a better solution than requiring developers to handle this themselves every time.
Activity
ajcvickers commentedon Nov 18, 2019
@TorreyGarland Putting this in the backlog to consider in the future. The global suppression seems like the best workaround for now.
Timovzl commentedon Nov 30, 2020
@ajcvickers @TorreyGarland Could either of you provide an example of such a global supression? I'm trying to get them to work, but with no success.
I did read somewhere that the
NamespaceAndDescendantsscope was broken in VS 16.7, and that it would be fixed in 16.8. I'm now on 16.8.2, but the suppression is not helping.roji commentedon Nov 30, 2020
I think that by global suppression, it was meant that you don't activate the NRT feature at the project level (i.e.
<Nullable>disabled</Nullable>). You can place your migrations in a separate project to keep nullability enabled in your actual code, if you want.Another option is to place a
#nullable disableat the top of each migration file.roji commentedon Nov 30, 2020
Clearing milestone to discuss if we want to do something for 6.0.
Timovzl commentedon Nov 30, 2020
@roji I'm pretty sure global suppressions is generally the term for what I mentioned above, so I assume that's what @TorreyGarland meant. I can't see why it's not working, though.
Disabling nullable for the entire project is too impactful, unfortunately. Adding
#nullable disableat the top of each migration file would work, as would disabling the warnings from those locations.I'm still hoping for a solution that makes the problem go away, instead of requiring each developer to remember for each new migration. We have "treat warnings as errors" enabled in the DevOps pipeline, to prevent the solution from becoming riddled with warnings... so it's quite a nuisance. 😛
roji commentedon Nov 30, 2020
You're right - global suppressions should indeed also work, I'm not sure why the above doesn't. I also agree we should provide a better solution than requiring developers to handle this themselves every time.
16 remaining items
roji commentedon Jan 24, 2022
Scenarios:
new object[])HasDatagenerates migration withobject[,]instead ofobject?[,]#25588 as a duplicate of this issue