FakeItEasy.Core.FakeCreationException while creating (many) fakes
See original GitHub issueWe are using FakeItEasy 2.0.0 and are creating thousands of fake objects during our unit-tests. Unfortunately we get a FakeItEasy.Core.FakeCreationException
occasionally in different test-classes for different fake-objects on our CI:
MESSAGE:
SetUp : FakeItEasy.Core.FakeCreationException :
Failed to create fake of type "IConditionElementCollector".
Below is a list of reasons for failure per attempted constructor:
No constructor arguments failed:
No usable default constructor was found on the type IConditionElementCollector.
An exception of type System.InvalidOperationException was caught during this call. Its message was:
Collection was modified; enumeration operation may not execute.
bei System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
bei System.Collections.Generic.List`1.Enumerator.MoveNextRare()
bei System.Collections.Generic.List`1.Enumerator.MoveNext()
bei Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.AddCustomAttributes(ProxyGenerationOptions proxyGenerationOptions)
bei Castle.DynamicProxy.Generators.BaseProxyGenerator.CreateTypeAttributes(ClassEmitter emitter)
bei Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope)
bei Castle.DynamicProxy.Generators.ClassProxyGenerator.<>c__DisplayClass1.<GenerateCode>b__0(String n, INamingScope s)
bei Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
bei Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
bei Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
bei Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
bei FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyGenerator.GenerateClassProxy(Type typeOfProxy, IEnumerable`1 argumentsForConstructor, IInterceptor interceptor, IEnumerable`1 allInterfacesToImplement)
bei FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyGenerator.DoGenerateProxy(Type typeOfProxy, IEnumerable`1 additionalInterfacesToImplement, IEnumerable`1 argumentsForConstructor, IInterceptor interceptor)
bei FakeItEasy.Creation.CastleDynamicProxy.CastleDynamicProxyGenerator.CreateProxyGeneratorResult(Type typeOfProxy, IEnumerable`1 additionalInterfacesToImplement, IEnumerable`1 argumentsForConstructor, IFakeCallProcessorProvider fakeCallProcessorProvider)
+++++++++++++++++++
STACK TRACE:
bei FakeItEasy.Core.DefaultExceptionThrower.ThrowFailedToGenerateProxyWithResolvedConstructors(Type typeOfFake, String reasonForFailureOfUnspecifiedConstructor, IEnumerable`1 resolvedConstructors)
bei FakeItEasy.Creation.FakeObjectCreator.TryCreateFakeWithDummyArgumentsForConstructor(Type typeOfFake, IProxyOptions proxyOptions, IDummyValueCreationSession session, String failReasonForDefaultConstructor, Boolean throwOnFailure)
bei FakeItEasy.Creation.FakeObjectCreator.CreateFake(Type typeOfFake, IProxyOptions proxyOptions, IDummyValueCreationSession session, Boolean throwOnFailure)
bei FakeItEasy.Creation.DefaultFakeAndDummyManager.CreateFake(Type typeOfFake, Action`1 optionsBuilder)
bei FakeItEasy.Creation.DefaultFakeCreatorFacade.CreateFake[T](Action`1 optionsBuilder)
bei FakeItEasy.A.Fake[T]()
bei VisibilityPropertyHandlerTest.Setup()
Any idea, how to fix this Heisenbug? The tests are running sequentially on the CI (no tests are running concurrently). It happens about once every week at different locations, usually where a lot of fakes are created rapidly: in the unit-tests.
Issue Analytics
- State:
- Created 7 years ago
- Comments:17 (14 by maintainers)
Top Results From Across the Web
Creating a fake DbDataAdapter throws FakeItEasy.Core. ...
Usually such problems come not from FakeItEasy itself, but from Castle.DynamicProxy, library which FakeItEasy uses to create fake types.
Read more >Creating Fakes
Fake <IFoo>();. This will return a faked object that is an actual instance of the type specified ( IFoo in this case).
Read more >Creating a fake DbDataAdapter throws FakeItEasy.Core ...
[Solved]-Creating a fake DbDataAdapter throws FakeItEasy.Core.FakeCreationException-C# · You need to reference Castle.Core. · Keep in mind FakeItEasy will only be ...
Read more >C# Mocking Made SUPER SIMPLE with Fake It Easy - YouTube
... MORE C# LESSONS http://bit.ly/mytestedaspnet In this video, I show how easy it is to create fake objects in your C# unit tests....
Read more >fakeiteasy - Archive
ID Status Summary
6 Fixed Add callbacks Type‑Enhancement Priority‑High
5 Fixed Create fake objects Type‑Defect Priority‑High
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think so… @apacha, your tests are run serially, but are you sure the tested code doesn’t spawn threads that could indirectly create fakes (e.g. by calling an unconfigured method on a fake)?
@thomaslevesque, I think your analysis is spot on, but can’t see any way for there to be a problem if tests are run serially. Only concurrent fake creation should be a problem, no?