MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.32k stars 329 forks source link

Issue creating config with Include when testing #612

Open JoMiGe opened 1 year ago

JoMiGe commented 1 year ago

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.Include[TDerivedSource,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 ?

benjaminoerskov commented 10 months ago

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

Jofrais commented 9 months ago

Got the same issue here...