question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

An new ArgumentException is throw(already catched) with Navigation Property in EFCore2.1?

See original GitHub issue

Describe what is not working as expected.

An new ArgumentException is throw as FirstChanceException(already catched in EntityQueryModelVisitor.ShiftMemberAccess) in EFCore2.1-preview2, and that never happened in EFCore2.0. Is this behavior work as excepted? Seems not affact the result and not break program, but it’s annoying when debug program or do log with FirstChanceException.

BTW(may not related to the issue): Since QuerySourceMapping.RemoveMapping is available now in Relinq, should it be used somewhere, according to the comment in the catch in ShiftMemberAccess if it’s really stale?

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception message: System.ArgumentException: Field 'Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[AAA,System.Collections.Generic.IEnumerable`1[BBB]].Inner' is not defined for type 'Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[AAA,BBB]'
Stack trace:

   at System.Linq.Expressions.Expression.Field(Expression expression, FieldInfo field)
   at System.Environment.get_StackTrace()
   at ConsoleApp15.Program.<>c.<Main>b__0_0(Object sender, FirstChanceExceptionEventArgs ev) in c:\users\yyjde_000\documents\visual studio 2017\Projects\ConsoleApp15\ConsoleApp15\Program.cs:line 11
   at System.Linq.Expressions.Expression.Field(Expression expression, FieldInfo field)
   at System.Linq.Expressions.Expression.MakeMemberAccess(Expression expression, MemberInfo member)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ShiftMemberAccess(Expression targetExpression, Expression currentExpression)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.IntroduceTransparentScope(IQuerySource querySource, QueryModel queryModel, Int32 index, Type transparentIdentifierType)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitGroupJoinClause(GroupJoinClause groupJoinClause, QueryModel queryModel, Int32 index)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitGroupJoinClause(GroupJoinClause groupJoinClause, QueryModel queryModel, Int32 index)
   at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
   at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database, IDiagnosticsLogger`1 logger, Type contextType)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass13_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Remotion.Linq.QueryableBase`1.GetEnumerator()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

Steps to reproduce

Include a complete code listing (or project/solution) that we can run to reproduce the issue.

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.

            AppDomain.CurrentDomain.FirstChanceException += (sender, ev) => Console.WriteLine(ev.Exception + Environment.NewLine + Environment.StackTrace);
            using (var ctx = new TestContext())
            {
                //EntityQueryModelVisitor.TransparentIdentifier<AAA,IEnumerable<BBB>> vs 
                //EntityQueryModelVisitor.TransparentIdentifier<AAA,BBB>
                var a = ctx.Device
                    .Include(d => d.Type1)
                    .Include(d => d.Type2)
                    .ToList();

                //See difference after remove DictType1/DictType2(Type) or `DefaultIfEmpty()` or both
                var a2 = (from Device d in ctx.Device
                          join DictType2 t2 in ctx.DictType2 on d.Type2Id equals t2.Type2Id into t2g
                          from DictType2 t2 in t2g.DefaultIfEmpty()
                          join DictType1 t1 in ctx.DictType1 on d.Type1Id equals t1.Type1Id into t1g
                          from DictType1 t1 in t1g.DefaultIfEmpty()
                          select new { d, t1, t2 }).ToList();

                var b = ctx.Device
                    .Include(d => d.Type1)
                    .Where(d => d.Group.Status == 0)
                    .ToList();

                //Exception Message with different Type
                //EntityQueryModelVisitor.TransparentIdentifier<ValueBuffer,IEnumerable<ValueBuffer>> vs 
                //EntityQueryModelVisitor.TransparentIdentifier<EntityQueryModelVisitor.TransparentIdentifier<ValueBuffer,ValueBuffer>,ValueBuffer>
                var c = ctx.Device
                    .Select(d=>new
                    {
                        d.DeviceId,
                        Type1Name = d.Type1.Type1Name,
                        NameA = d.RawANavigation.Raw2.Raw2Name,
                    })
                    .ToList();
            }

The table struct like this

    public partial class Device
    {
        public int DeviceId { get; set; }
        public int? Type1Id { get; set; }
        public int? Type2Id { get; set; }
        public int GroupId { get; set; }
        public int? RawA { get; set; }
        public int? RawB { get; set; }
        public int? RawC { get; set; }

        public Group Group { get; set; }
        public Raw RawANavigation { get; set; }
        public Raw RawBNavigation { get; set; }
        public Raw RawCNavigation { get; set; }
        public DictType1 Type1 { get; set; }
        public DictType2 Type2 { get; set; }
    }
    public partial class DictType1
    {
        public DictType1()
        {
            Device = new HashSet<Device>();
            DictType2 = new HashSet<DictType2>();
        }

        public int Type1Id { get; set; }
        public string Type1Name { get; set; }

        public ICollection<Device> Device { get; set; }
        public ICollection<DictType2> DictType2 { get; set; }
    }
    public partial class DictType2
    {
        public DictType2()
        {
            Device = new HashSet<Device>();
        }

        public int Type2Id { get; set; }
        public string Type2Name { get; set; }
        public int? Type1Id { get; set; }

        public DictType1 Type1 { get; set; }
        public ICollection<Device> Device { get; set; }
    }
    public partial class Group
    {
        public Group()
        {
            Device = new HashSet<Device>();
        }

        public int GroupId { get; set; }
        public byte Status { get; set; }

        public ICollection<Device> Device { get; set; }
    }
    public partial class Raw
    {
        public Raw()
        {
            DeviceRawANavigation = new HashSet<Device>();
            DeviceRawBNavigation = new HashSet<Device>();
            DeviceRawCNavigation = new HashSet<Device>();
        }

        public int RawId { get; set; }
        public int? Raw2Id { get; set; }

        public Raw2 Raw2 { get; set; }
        public ICollection<Device> DeviceRawANavigation { get; set; }
        public ICollection<Device> DeviceRawBNavigation { get; set; }
        public ICollection<Device> DeviceRawCNavigation { get; set; }
    }
    public partial class Raw2
    {
        public Raw2()
        {
            Raw = new HashSet<Raw>();
        }

        public int Raw2Id { get; set; }
        public string Raw2Name { get; set; }

        public ICollection<Raw> Raw { get; set; }
    }

Further technical details

EF Core version: 2.1.0-preview1-final/2.1.0-preview2-final/2.1.0-rc1-30631(from myget/aspnetcore-dev) Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Win10 x64 17650 Insider Preview IDE: Visual Studio 2017 15.7.0preview4

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:15
  • Comments:25 (8 by maintainers)

github_iconTop GitHub Comments

12reactions
ajcvickerscommented, Nov 9, 2018

Since multiple people are commenting on this I want to clarify the situation. We would love to fix this now, but the problem is that the exception is thrown by a third-party dependency, and the try-catch in the EF code is a workaround for that exception. We are removing that dependency in 3.0 and hence this will no longer be an issue. Now obviously if this was causing many people’s running apps to fail, then we would have to look into doing something more drastic sooner. However, that’s not the case with this issue. It’s only a problem in some scenarios when using the debugger, and there are workarounds even for that. It’s unfortunate that this is resulting in a bad experience for some people when debugging and I wish that wasn’t the case, but in the grand scheme of things this still doesn’t feel like a critical issue that must be patched before 3.0.

9reactions
Pelias2525commented, Oct 26, 2018

I’m having this issue as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

An new ArgumentException is throw(already catched) with ...
An new ArgumentException is throw as FirstChanceException(already ... is throw(already catched) with Navigation Property in EFCore2.1?
Read more >
EF Core non nullable navigation properties - Best practice
EF Navigation properties will always need to be nullable, ... Make, make ) ) throw new ArgumentException( message: "Mismatched Car.
Read more >
Breaking changes in EF Core 6.0
New behavior. This action will now throw an exception: The property '{entityType}.{property}' is part of a key and so cannot be modified or ......
Read more >
dotConnect for MySQL History
The new property Validation Framework is implemented in the Data Transfer Object ... 1 on a diagram in EF Core Model; The bug...
Read more >
Don't let Entity Framework call the shots - Fear of Oblivion
If there is one thing you take away from this post, it is that EF is there to map data from the database...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found