Skip to content
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

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

Closed
P9avel opened this issue Jan 22, 2023 · 11 comments · Fixed by #30537
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Milestone

Comments

@P9avel
Copy link

P9avel commented Jan 22, 2023

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

@roji
Copy link
Member

roji commented Jan 22, 2023

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.

@P9avel
Copy link
Author

P9avel commented Jan 22, 2023

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

@ajcvickers
Copy link
Contributor

@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.

@roji
Copy link
Member

roji commented Jan 24, 2023

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.

@P9avel
Copy link
Author

P9avel commented Jan 25, 2023

Hello. I see you, am try creating small example

@ajcvickers
Copy link
Contributor

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 ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2023
@ioan-toader
Copy link

ioan-toader commented Mar 15, 2023

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

@ajcvickers
Copy link
Contributor

Note from triage: @maumar to investigate.

maumar added a commit that referenced this issue Mar 21, 2023
…Expression(Expression sourceExpression, IEntityType entityType) / get_Chars(Int32 index) when EF class named "<>f__AnonymousType01Child" in 7.0.2 version

Check if ShortName returns empty string, and if so use token parameter name.

Fixes #30115
@maumar maumar added type-bug closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels Mar 21, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0, 7.0.x Mar 22, 2023
maumar added a commit that referenced this issue Mar 28, 2023
…Expression(Expression sourceExpression, IEntityType entityType) / get_Chars(Int32 index) when EF class named "<>f__AnonymousType01Child" in 7.0.2 version

Adjusting ShortName to trim "<>" from the start of the type name.

Fixes #30115
maumar added a commit that referenced this issue Mar 28, 2023
…Expression(Expression sourceExpression, IEntityType entityType) / get_Chars(Int32 index) when EF class named "<>f__AnonymousType01Child" in 7.0.2 version

Adjusting ShortName to trim "<>" from the start of the type name.

Fixes #30115
maumar added a commit that referenced this issue Mar 28, 2023
…Expression(Expression sourceExpression, IEntityType entityType) / get_Chars(Int32 index) when EF class named "<>f__AnonymousType01Child" in 7.0.2 version (#30537)

Adjusting ShortName to trim "<>" from the start of the type name.

Fixes #30115
@maumar
Copy link
Contributor

maumar commented Mar 28, 2023

reopen for potential servicing

maumar added a commit that referenced this issue Mar 28, 2023
…Expression(Expression sourceExpression, IEntityType entityType) / get_Chars(Int32 index) when EF class named "<>f__AnonymousType01Child" in 7.0.2 version

Adjusting ShortName to trim "<>" from the start of the type name.

Fixes #30115
maumar added a commit that referenced this issue Mar 28, 2023
…Expression(Expression sourceExpression, IEntityType entityType) / get_Chars(Int32 index) when EF class named "<>f__AnonymousType01Child" in 7.0.2 version

Adjusting ShortName to trim "<>" from the start of the type name.

Fixes #30115
@P9avel
Copy link
Author

P9avel commented May 31, 2023

When you planning build 7.0.6 ?

@ErikEJ
Copy link
Contributor

ErikEJ commented May 31, 2023

@P9avel Second Tuesday of June

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment