Skip to content

thread-safety issue with TypeAdapterConfig #86

@centur

Description

@centur

Today after running a large suit of tests at once I saw one test failed with this exeption

System.ArgumentException
Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
   at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
   at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex)
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.<ReverseIterator>d__74`1.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Mapster.TypeAdapterConfig.GetMergedSettings(Type sourceType, Type destinationType, MapType mapType)
   at Mapster.TypeAdapterConfig.CreateMapExpression(Type sourceType, Type destinationType, MapType mapType, CompileContext context)
   at Mapster.TypeAdapterConfig.CreateInlineMapExpression(Type sourceType, Type destinationType, MapType mapType, CompileContext context)
   at Mapster.Adapters.BaseAdapter.CreateAdaptExpression(Expression source, Type destinationType, CompileArgument arg)
   at Mapster.Adapters.CollectionAdapter.CreateArraySet(Expression source, Expression destination, CompileArgument arg)
   at Mapster.Adapters.BaseAdapter.CreateBlockExpressionBody(Expression source, Expression destination, CompileArgument arg)
   at Mapster.Adapters.BaseAdapter.CreateExpressionBody(Expression source, Expression destination, CompileArgument arg)
   at Mapster.Adapters.BaseAdapter.CreateAdaptFunc(CompileArgument arg)
   at Mapster.TypeAdapterConfig.CreateMapExpression(Type sourceType, Type destinationType, MapType mapType, CompileContext context)
   at Mapster.TypeAdapterConfig.CreateMapFunction(TypeTuple tuple)
   at Mapster.TypeAdapterConfig.Compile()
   at DBCloud.WebAPI.WebDTOMapSetup.VerifyConfiguration() in C:\Projects\Drawboard.Cloud\DBCloud.WebAPI\App_Start\WebDTOMapSetup.cs:line 159

It never happened before, test is very simple and on a second run this error disappeared.
But after checking the error I found this interesting SO thread

Could it be that Mapster has some locking issues ?
PS: error originates from this call

        public static void VerifyConfiguration()
        {
            TypeAdapterConfig.GlobalSettings.Compile();
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions