-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add Migration NullReferenceException after EF Core 8 upgrade #33318
Comments
As always, there's little we can do with just an exception stacktrace, and no code showing how it got generated... Are you able to submit a minimal, runnable code sample showing this happening?
I wouldn't recommend doing this - the total amount of work in moving two versions separately can very well be larger than going from 6 to 8.
This is an expected, documented change - the provider supports the multirange types introduced in PostgreSQL 14, and by default maps range arrays to them. The odd thing is that this change was already done in EFCore.PG 6, so you should have already seen it.
This doesn't sound familiar - please open an issue in the EFCore.PG repo with a minimal, runnable sample.
Similarly, please open an issue on the PG side with a runnable code sample. |
Hi @roji, Thanks for the reply, I hadn't originally put code samples as there is a quiet a bit of code, and I have no idea where this exception is coming from, i.e. which model or column is causing this issue. So I don't know what sample to give other than the whole project which I can't. I was kind of hoping that from the stack trace someone might have been able to point me at some general things that could be causing this. I know that is not straight forward. I did the 6 -> 7 -> 8 to also confirm that the exception was being caused by 8 and not something introduced by 7. But from your comments I can happily shuffle things now to jump straight to 8. As for the other issues, I will get around to them, want to see if solving this might solve the others consequently. I am going to see if I can narrow it down further, and provide a sample if/when I can, but in the meantime, if you are aware of anything obvious in the behaviour in ef core 8 that might cause this issue based on where the exception is from to help me narrow things down would be much appreciated. |
@DizzyDeveloper thank you, maybe one of the other team members will have an idea (/cc @maumar, @ajcvickers). |
Heya @roji Also sussed out the other issues where it was altering the column types, other than the So I am closing up the issue as there isn't more on this at the moment. However, it would be nice if the ef core tools printed out the table and column that it was processing on when it encounters an exception, especially in this case. I attached a debugger to see what the column the tool was processing when it encounter the null reference exception. |
@DizzyDeveloper thanks for the info - makes sense.
If I'm following correctly, the exception above is of the kind that is "not supposed to happen" (i.e. developer bug in provider code), only because you were changing an internal service (NpgsqlTypeMappingSource) - it's generally not really feasible to catch these and add information, unfortunately, since they can occur almost anywhere... |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
It really would be nice to have more information about these NullReferenceException. I'm now fighting with mystic NullReferenceError when removing a migration. I'm new to ef migrations and it's really difficult to reason what might be wrong. |
I am running this problem as well |
We are currently upgrade from .net 6 to .net 8, and subsequently from ef core 6 to ef core 8.
After performing the upgrade I attempted to generate an arbitrary migration, however, the add migration call
dotnet ef migrations add Test --context DatabaseContext --verbose
fails.I end up with a null reference exception as below:
Furthermore, to try and reduce the size of the jump from ef core 6 to 8, I first upgrade to ef core 7, and ran the same add migration call as above. After this upgrade the migration ran happily, generating empty up/down steps, and updating the context snapshot , in a manner the appears appropriate.
After this upgrade (and leaving the generated context snapshot in place) I upgrade to ef core 8 (particularly 8.0.3), and ran the add migration call I mentioned above, and received the aforementioned null reference exception.
Additionally
If, however, I delete the context snapshot before running the add migration call, then the add migration call does succeed. But as you can expect the up/down steps wants to re-create the whole db. That is fine as I can just nuke those migration files, however, the snapshot comparison now shows changes that are concerning where it changes column types i.e. from
int4range[]
toint4multirange
andtext
tocharacter varying(13)
. Note there has been no changes in the models themselves.But ignore those things the migration does work. However, this leads on to another issue when running some of our migration tests. Particularly I end up with this exception.
But lets ignore that exception for now.
EF Core version: 8.0.3
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: .NET 8.0
Operating system: Windows 10
IDE: Rider 2023.3.4
The text was updated successfully, but these errors were encountered: