Mapster icon indicating copy to clipboard operation
Mapster copied to clipboard

Issue creating config with Include when testing

Open JoMiGe opened this issue 1 year ago • 2 comments

We have developed a service using Mapster to map our model and more particularly the Include method to configure the mapping.

    public TypeAdapterSetter<TSource, TDestination> Include<TDerivedSource, TDerivedDestination>()
      where TDerivedSource : class, TSource
      where TDerivedDestination : class, TDestination
    {
      return this.Include<TypeAdapterSetter<TSource, TDestination>>(typeof (TDerivedSource), typeof (TDerivedDestination));
    }

The issue happens when we run the tests (Integration tests). If the test is run unitary, it works. But when all the tests are run, we have the following exception on some tests.

System.ArgumentOutOfRangeException capacity was less than the current size. (Parameter 'value') at System.Collections.Generic.List1.set_Capacity(Int32 value) at System.Collections.Generic.List1.Grow(Int32 capacity) at System.Collections.Generic.List1.AddWithResize(T item) at Mapster.TypeAdapterSetterExtensions.Include[TSetter](TSetter setter, Type sourceType, Type destType) at Mapster.TypeAdapterSetter2.IncludeTDerivedSource,TDerivedDestination

The code is:

        TypeAdapterConfig<ConfigurationModel, Configuration>
            .NewConfig()
            .Include<AValueModel, AValue>()
            .Include<BValueModel, BValue>()
            .Include<CValueModel,DValue>();

Any idea what could be the issue ?

Thank you ?

JoMiGe avatar Jul 21 '23 15:07 JoMiGe

Im getting the same error. Did you figure out how to fix it?

benjaminoerskov avatar Nov 24 '23 08:11 benjaminoerskov

Got the same issue here...

Jofrais avatar Dec 19 '23 14:12 Jofrais