0

Since this morning, our CI build failed due to surprising "System.ArgumentException : Duplicate type name within an assembly." exceptions during our tests execution.

(note: our tests project built in .NET (4.6) using references to NUnit (3.9.0.0) and NSubstitute (3.1.0.0).

So far we have step into mscorlib (ModuleBuilder type) and found out that Castle.DynamicProxy was dynamically generating an assembly to host its stubs/fakes/ named: DynamicProxyGenAssembly2. And it seems that we had more than one reference for type named "Castle.Proxies.IEnumerator`1Proxy_13".

We don't really understand what's going on here. We appreciate any suggestion on how to understand and find out a solution.

Stack trace example: -----------------

at System.Reflection.Emit.ModuleBuilder.CheckTypeNameConflict(String strTypeName, Type enclosingType) at System.Reflection.Emit.AssemblyBuilderData.CheckTypeNameConflict(String strTypeName, TypeBuilder enclosingType) at System.Reflection.Emit.TypeBuilder.Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, ModuleBuilder module, PackingSize iPackingSize, Int32 iTypeSize, TypeBuilder enclosingType) at System.Reflection.Emit.ModuleBuilder.DefineTypeNoLock(String name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packingSize, Int32 typesize) at System.Reflection.Emit.ModuleBuilder.DefineType(String name, TypeAttributes attr) at Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, String name, Type baseType, IEnumerable1 interfaces, TypeAttributes flags, Boolean forceUnsigned) at Castle.DynamicProxy.Generators.Emitters.ClassEmitter..ctor(ModuleScope modulescope, String name, Type baseType, IEnumerable1 interfaces) at Castle.DynamicProxy.Generators.BaseProxyGenerator.BuildClassEmitter(String typeName, Type parentType, IEnumerable1 interfaces) at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.Init(String typeName, ClassEmitter& emitter, Type proxyTargetType, FieldReference& interceptorsField, IEnumerable1 interfaces) at Castle.DynamicProxy.Generators.InterfaceProxyWithoutTargetGenerator.GenerateType(String typeName, Type proxyTargetType, Type[] interfaces, INamingScope namingScope) at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.<>c__DisplayClass6_0.b__0(String n, INamingScope s) at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func3 factory) at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors) at NSubstitute.Proxies.CastleDynamicProxy.CastleDynamicProxyFactory.GenerateProxy(ICallRouter callRouter, Type typeToProxy, Type[] additionalInterfaces, Object[] constructorArguments) at NSubstitute.Core.SubstituteFactory.Create(Type[] typesToProxy, Object[] constructorArguments, SubstituteConfig config) at NSubstitute.Routing.Handlers.ReturnAutoValue.<>c__DisplayClass6_0.<ReturnValueUsingProvider>b__0(IAutoValueProvider provider) at NSubstitute.Routing.Handlers.ReturnAutoValue.Handle(ICall call) at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source, Func2 predicate) at NSubstitute.Routing.Route.Handle(ICall call) at NSubstitute.Proxies.CastleDynamicProxy.CastleForwardingInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.Proxies.IEnumerable1Proxy_16.GetEnumerator() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at Caraibes.Infrastructure.AggregateCreationAuditTrail.BuildCacheFromEventStore(AggregateType aggregateType) in E:\Builds\TheFuture01_work\366\s\Caraibes\Caraibes.Infrastructure\AggregateCreationAuditTrail.cs:line 45 at Caraibes.Infrastructure.AggregateCreationAuditTrail.HasAlreadyBeenCreated(AggregateType aggregateType, Int32 lightTradeId) in E:\Builds\TheFuture01_work\366\s\Caraibes\Caraibes.Infrastructure\AggregateCreationAuditTrail.cs:line 31 at Caraibes.Tests.Domain.EventSourcing.AggregateCreationAuditTrailShould.Only_call_EventStore_when_previous_request_did_not_contained_the_requested_identifier(AggregateType aggregateType) in E:\Builds\TheFuture01_work\366\s\Caraibes\Caraibes.Tests\Domain\EventSourcing\AggregateCreationAuditTrailShould.cs:line 74 Attachments (0)

yi.han
  • 369
  • 4
  • 8
  • Does this fail all the time, or just intermittently? Are you able to post the failing code and associated interfaces? (or a simplified/equivalent version if the code is private?) – David Tchepak Mar 15 '18 at 21:52
  • 1
    It fails in our Unit tests: random failure on a certain tests for each run; when run individually on failed tests => OK. We are about to find the root cause, It seems that it was due to a side affect used: NSubstitute and DeepCloner. I will post it when dig more into it and formulate the full explaination. – yi.han Mar 16 '18 at 08:50
  • @yi.han any updates on this? I am probably running into the same problem, but using XUnit – mvaneijk Apr 08 '19 at 12:50

0 Answers0