Intermittent System.TypeLoadExceptions and System.Security.VerificationExceptions
See original GitHub issueVersion: 7.3.1
Castle.Core version: 4.3.1.
After upgrading our solution from .NET 4.8 to .NET 6 we have seen intermittent (about one failed run in every 6-7 build server test runs) System.TypeLoadExceptions and System.Security.VerificationExceptions with the following messages:
System.Security.VerificationException example:
System.ArgumentException GenericArguments[0], 'CompanyName.OurType[]', on 'T ExecuteLegacyQuery[T](CompanyName.IQuery`1[T])' violates the constraint of type 'T'.
---- System.Security.VerificationException Method Castle.Proxies.ObjectProxy_35.ExecuteLegacyQuery type argument 'CompanyName.OurType[]' violates the constraint of type parameter 'T'.
at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
at FakeItEasy.Core.MethodInfoManager.MakeGeneric(MethodInfo methodToMakeGeneric, MethodInfo originalMethod) in CprojectsfakeiteasysrcFakeItEasyCoreMethodInfoManager.csline 112
at FakeItEasy.Core.MethodInfoManager.c__DisplayClass5_0.GetMethodOnTypeThatImplementsInterfaceMethodb__2(f__AnonymousType4`2 methodTargetPair) in CprojectsfakeiteasysrcFakeItEasyCoreMethodInfoManager.csline 102
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at FakeItEasy.Core.MethodInfoManager.GetMethodOnTypeThatImplementsInterfaceMethod(Type type, MethodInfo method) in CprojectsfakeiteasysrcFakeItEasyCoreMethodInfoManager.csline 98
at FakeItEasy.Core.MethodInfoManager.FindMethodOnTypeThatWillBeInvokedByMethodInfo(Type type, MethodInfo method) in CprojectsfakeiteasysrcFakeItEasyCoreMethodInfoManager.csline 46
at FakeItEasy.Core.MethodInfoManager.c.GetMethodOnTypeThatWillBeInvokedByMethodInfob__2_0(TypeMethodInfoPair k) in CprojectsfakeiteasysrcFakeItEasyCoreMethodInfoManager.csline 41
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at FakeItEasy.Core.MethodInfoManager.GetMethodOnTypeThatWillBeInvokedByMethodInfo(Type type, MethodInfo method) in CprojectsfakeiteasysrcFakeItEasyCoreMethodInfoManager.csline 41
at FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyInterceptionValidator.GetInvokedMethod(MethodInfo method, Object callTarget) in CprojectsfakeiteasysrcFakeItEasyCreationCastleDynamicProxyCastleDynamicProxyInterceptionValidator.csline 79
at FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyInterceptionValidator.MethodCanBeInterceptedOnInstance(MethodInfo method, Object callTarget, String& failReason) in CprojectsfakeiteasysrcFakeItEasyCreationCastleDynamicProxyCastleDynamicProxyInterceptionValidator.csline 20
at FakeItEasy.Creation.FakeObjectCreator.DefaultCreationStrategy.MethodCanBeInterceptedOnInstance(MethodInfo method, Object callTarget, String& failReason) in CprojectsfakeiteasysrcFakeItEasyCreationFakeObjectCreator.csline 184
at FakeItEasy.Creation.FakeObjectCreator.MethodCanBeInterceptedOnInstance(MethodInfo method, Object callTarget, String& failReason) in CprojectsfakeiteasysrcFakeItEasyCreationFakeObjectCreator.csline 76
at FakeItEasy.Configuration.DefaultInterceptionAsserter.AssertThatMethodCanBeInterceptedOnInstance(MethodInfo method, Object callTarget) in CprojectsfakeiteasysrcFakeItEasyConfigurationDefaultInterceptionAsserter.csline 19
at FakeItEasy.Configuration.FakeConfigurationManager.AssertThatMemberCanBeIntercepted(ParsedCallExpression parsed) in CprojectsfakeiteasysrcFakeItEasyConfigurationFakeConfigurationManager.csline 96
at FakeItEasy.Configuration.FakeConfigurationManager.CallTo[T](Expression`1 callSpecification) in CprojectsfakeiteasysrcFakeItEasyConfigurationFakeConfigurationManager.csline 46
at FakeItEasy.A.CallTo[T](Expression`1 callSpecification) in CprojectsfakeiteasysrcFakeItEasyA.csline 161
System.TypeLoadException example:
System.TypeLoadException : GenericArguments[0], 'T', on 'Castle.Proxies.Invocations.ISqlDatabase_ExecuteQueryAsync_1[TEvent]' violates the constraint of type parameter 'TEvent'.
at Castle.Proxies.ObjectProxy_63.ExecuteQueryAsync[T](String sql, Object param, CancellationToken cancellationToken, Nullable`1 commandTimeout)
The common part about all these exceptions is the error about violating the constraint of type parameter and that they are all related to mocks.
I don’t believe that this issue directly related to the FakeItEasy, but rather to the underlying library - Castle.Core.
Creating this issue for visibility.
Similar issue with moq4: https://github.com/moq/moq4/issues/1145
The issue on the Castle.Core side: https://github.com/castleproject/Core/issues/193
Issue Analytics
- State:
- Created 8 months ago
- Comments:12 (6 by maintainers)
Top GitHub Comments
Thanks for continuing on this, @maxcherednik. I wonder, though. The leading though is that a problem is in or below the Castle.Core project, it may be a better use of your time to follow up exclusively in https://github.com/castleproject/Core/issues/193. Then you don’t have to duplicate your efforts, and people can read all the details in one place…
(The Castle.Core code is largely over my head, and I given work and home commitments, I doubt I’m going to get enough time to educate myself and start contributing in the near future.)
No idea. FakeItEasy does not create (or change) generic parameters called “TEvent”, as far as I can tell. Nor does a quick search in GitHub reveal anything like that in the Castle.Core source.