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.

IEnumerable and IReadOnlyCollection navigation properties throw System.Security.VerificationException

See original GitHub issue

This is the same exception that has been discussed a few years back in several issues: https://github.com/dotnet/efcore/issues/12881 https://github.com/dotnet/efcore/issues/12558 https://github.com/dotnet/efcore/issues/12925 . It was apparently made moot by QueryBuffer being removed, but it still occurs.

It appears that the problem has returned; using IReadOnlyCollection or IEnumerable in place of ICollection causes an exception:

System.ArgumentException: GenericArguments[1], 'System.Collections.Generic.IReadOnlyCollection`1[CCServer.Data.Principals.Principal]', on 'TCollection InitializeCollection[TElement,TCollection](Int32, Microsoft.EntityFrameworkCore.Query.QueryContext, System.Data.Common.DbDataReader, Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryResultCoordinator, System.Func`3[Microsoft.EntityFrameworkCore.Query.QueryContext,System.Data.Common.DbDataReader,System.Object[]], System.Func`3[Microsoft.EntityFrameworkCore.Query.QueryContext,System.Data.Common.DbDataReader,System.Object[]], Microsoft.EntityFrameworkCore.Metadata.IClrCollectionAccessor)' violates the constraint of type 'TCollection'.
 ---> System.Security.VerificationException: Method Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor+ShaperProcessingExpressionVisitor.InitializeCollection: type argument 'System.Collections.Generic.IReadOnlyCollection`1[CCServer.Data.Principals.Principal]' violates the constraint of type parameter 'TCollection'.
   at System.RuntimeMethodHandle.GetStubIfNeeded(RuntimeMethodHandleInternal method, RuntimeType declaringType, RuntimeType[] methodInstantiation)
   at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
   --- End of inner exception stack trace ---
   at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
   at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.VisitExtension(Expression extensionExpression)
   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.ProcessShaper(Expression shaperExpression, RelationalCommandCache& relationalCommandCache, LambdaExpression& relatedDataLoaders, Int32& collectionId)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.VisitShapedQuery(ShapedQueryExpression shapedQueryExpression)
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.VisitExtension(Expression extensionExpression)
   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.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_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source) in D:\a\_work\1\s\src\fsharp\FSharp.Core\seq.fs:line 803
   at <StartupCode$FSI_0004>.$FSI_0004.main@()

Include provider and version information

EF Core version: 6.0.0 Database provider: (e.g. Npgsql.EntityFrameworkCore.PostgreSQL) Target framework: (e.g. .NET 6.0) Operating system: Windows 11 IDE: (e.g. Visual Studio 2022 17.0)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
smitpatelcommented, Dec 6, 2021

This issue is lacking enough information for us to effectively reproduce. Please post a runnable project/solution or complete code listing that demonstrates the behavior you are seeing.

0reactions
cdrfenixcommented, Feb 1, 2023

See this issue please, it might be related: https://github.com/dotnet/efcore/issues/30195

Read more comments on GitHub >

github_iconTop Results From Across the Web

type argument IEnumerable`1[entity]' violates constraint of ...
ToListAsync() is executed, I get this exception: VerificationException: Method Microsoft. EntityFrameworkCore. Query.
Read more >
ICollection Errors Re: Navigation Properties - Microsoft Q&A
If it is a navigation, manually configure the relationship for this property by casting it to a mapped entity type.
Read more >
Functional Reactive Programming and HTML
This reactive system integrates with the HTML library to create reactive documents. ... Some attributes, notably class and type , are also C#...
Read more >
DotNet links from msdn.microsoft.com
Code Access Permissions; Identity Permissions; Role-Based Security Permissions ... VerificationException; Troubleshooting Exceptions: System.Security.
Read more >
恶意软件分析& URL链接扫描免费在线病毒分析平台
文件名, COD.apk. 文件大小, 6226275 字节. 文件类型, Zip archive data, at least v2.0 to extract. MD5, 4b0037d9afba664c3951165aa49f979f.
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 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