Repository: dotnet/efcore
File: src/EFCore/Infrastructure/Internal/LazyLoader.cs (C#)

Code before:

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    // ReSharper disable once AssignNullToNotNullAttribute
    public virtual void Load(object entity, [CallerMemberName] string navigationName = "")
    {
        Check.NotNull(entity, nameof(entity));
        Check.NotEmpty(navigationName, nameof(navigationName));

        var navEntry = (entity, navigationName);

        bool exists;
        TaskCompletionSource isLoadingValue;

        lock (_isLoadingLock)
        {
            ref var refIsLoadingValue = ref CollectionsMarshal.GetValueRefOrAddDefault(_isLoading, navEntry, out exists);
            if (!exists)
            {
                refIsLoadingValue = new();
            }
            s_isLoadingCallDepth.Value++;
            isLoadingValue = refIsLoadingValue!;
        }

        if (exists)
        {
            // Only waits for the outermost call on the call stack. See #35528.
            // if s_isLoadingCallDepth.Value > 1 the call is recursive, waiting probably generates a deadlock See #35832.
            if (s_isLoadingCallDepth.Value == 1)
            {
                isLoadingValue.Task.Wait();
            }
            return;
        }

        try
        {
            // ShouldLoad is called after _isLoading.Add because it could attempt to load the property. See #13138.
            if (ShouldLoad(entity, navigationName, out var entry))
            {
                try
                {
                    entry.Load(
                        _queryTrackingBehavior == QueryTrackingBehavior.NoTrackingWithIdentityResolution
                            ? LoadOptions.ForceIdentityResolution
                            : LoadOptions.None);

Review comment (suggestion):
```suggestion
            _isLoadingCallDepth.Value++;
```

Code after:

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    // ReSharper disable once AssignNullToNotNullAttribute
    public virtual void Load(object entity, [CallerMemberName] string navigationName = "")
    {
        Check.NotNull(entity, nameof(entity));
        Check.NotEmpty(navigationName, nameof(navigationName));

        var navEntry = (entity, navigationName);

        bool exists;
        TaskCompletionSource isLoadingValue;

        lock (_isLoadingLock)
        {
            ref var refIsLoadingValue = ref CollectionsMarshal.GetValueRefOrAddDefault(_isLoading, navEntry, out exists);
            if (!exists)
            {
                refIsLoadingValue = new();
            }
            _isLoadingCallDepth.Value++;
            isLoadingValue = refIsLoadingValue!;
        }

        if (exists)
        {
            // Only waits for the outermost call on the call stack. See #35528.
            // if _isLoadingCallDepth.Value > 1 the call is recursive, waiting probably generates a deadlock See #35832.
            if (_isLoadingCallDepth.Value == 1)
            {
                isLoadingValue.Task.Wait();
            }
            _isLoadingCallDepth.Value--;
            return;
        }

        try
        {
            // ShouldLoad is called after _isLoading.Add because it could attempt to load the property. See #13138.
            if (ShouldLoad(entity, navigationName, out var entry))
            {
                try
                {
                    entry.Load(
                        _queryTrackingBehavior == QueryTrackingBehavior.NoTrackingWithIdentityResolution
                            ? LoadOptions.ForceIdentityResolution