efcore icon indicating copy to clipboard operation
efcore copied to clipboard

IndexOutOfRangeException in CreateNavigationExpansionExpression(Expression sourceExpression, IEntityType entityType) / get_Chars(Int32 index) when EF class named "<>f__AnonymousType01Child" in 7.0.2 version

Open P9avel opened this issue 2 years ago • 5 comments

Hi, i am recived

---> System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.String.get_Chars(Int32 index) at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.CreateNavigationExpansionExpression(Expression sourceExpression, IEntityType entityType) at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitExtension(Expression extensionExpression) at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.Expand(Expression query) at Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(Expression query) at Microsoft.EntcityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query) at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_01.<Execute>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) at System.Linq.Queryable.Count[TSource](IQueryable`1 source)

when my EF Core class named '' "<>f__AnonymousType01Child" in 7.0.2 I am think issue in ShortName() implementation

P9avel avatar Jan 22 '23 15:01 P9avel

This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

roji avatar Jan 22 '23 16:01 roji

Sorry, i am cannot do it. I am used code generation in large application. In 6.x version all works. After upgrating to 7.0.2 ia get this exception. my EF Core class named ''<>f__AnonymousType01Child". Now i am did EF Core class named ''f__AnonymousType01Child" and all ok. I.e. enough remove <> as first symbols

P9avel avatar Jan 22 '23 16:01 P9avel

@P9avel We can't help here without enough information to understand what is going on. You will need to attempt to strip down your code to create a runnable repro.

ajcvickers avatar Jan 24 '23 10:01 ajcvickers

As @ajcvickers wrote, just posting an exception stack trace is very rarely enough. You'll need to provide us with the necessary information to allow us to reproduce the problem.

roji avatar Jan 24 '23 11:01 roji

Hello. I see you, am try creating small example

P9avel avatar Jan 25 '23 12:01 P9avel

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

ajcvickers avatar Feb 08 '23 19:02 ajcvickers

The problem is here:


 private NavigationExpansionExpression CreateNavigationExpansionExpression(
        Expression sourceExpression,
        IEntityType entityType)
    {
        // if sourceExpression is not a query root we will throw when trying to construct temporal root expression
        // regular queries don't use the query root so they will still be fine
        var entityReference = new EntityReference(entityType, sourceExpression as EntityQueryRootExpression);
        PopulateEagerLoadedNavigations(entityReference.IncludePaths);

        var currentTree = new NavigationTreeExpression(entityReference);
        var parameterName = GetParameterName(entityType.ShortName()[0].ToString().ToLowerInvariant());

        return new NavigationExpansionExpression(sourceExpression, currentTree, currentTree, parameterName);
    }


        var parameterName = GetParameterName(entityType.ShortName()[0].ToString().ToLowerInvariant());

ShortName property return empty string

    string ShortName()
    {
        if (!HasSharedClrType)
        {
            var name = ClrType.ShortDisplayName();
            var lessIndex = name.IndexOf("<", StringComparison.Ordinal);
            if (lessIndex == -1)
            {
                return name;
            }

            return name[..lessIndex];
        }

```In case the type start with < ShortName method return empty string

ioan-toader avatar Mar 15 '23 09:03 ioan-toader

Note from triage: @maumar to investigate.

ajcvickers avatar Mar 16 '23 13:03 ajcvickers

reopen for potential servicing

maumar avatar Mar 28 '23 17:03 maumar

When you planning build 7.0.6 ?

P9avel avatar May 31 '23 11:05 P9avel

@P9avel Second Tuesday of June

ErikEJ avatar May 31 '23 11:05 ErikEJ