Hidden Exception in LazyLoader.Load(..) Due to exception in InternalEntry.SetIsLoaded(..)
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
An exception thrown inside [the try section](https://github.com/dotnet/efcore/blob/20edb631265527a73cb9b9ab474cd0484c49a771/src/EFCore/Infrastructure/Internal/LazyLoader.cs#L118) in `LazyLoader.Load(..)` can be hidden by an exception thrown from the `InternalEntry.SetIsLoaded(..)` method.
In my case, I was using EFCore 8.0.6 and received the following exception:
> InvalidOperationException: The navigation 'EntityOne.EntityTwo' cannot have 'IsLoaded' set to false because the referenced entity is non-null and is therefore loaded.
Then, I forked and added logging[ before setting](https://github.com/dotnet/efcore/blob/20edb631265527a73cb9b9ab474cd0484c49a771/src/EFCore/Infrastructure/Internal/LazyLoader.cs#L125) `entry.IsLoaded = false` and got the original exception:
> Microsoft.Data.SqlClient.SqlException (0x80131904): Transaction (Process ID 739) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction. Which was not being propagated before the addition.
Unfortunately, reproducing the issue is quite complex and I cannot attach it.
### Include provider and version information
EF Core version: 8.0.6
Database provider: MsSqlServer
Target framework: net8
Operating system: ubuntu
Contributor guide
Assessment
This issue has not been assessed yet.