dd-trace-dotnet: AutoMapper throws EntryPointNotFoundException when profiler is enabled on Linux
Describe the bug
Unhandled Exception: System.EntryPointNotFoundException: Entry point was not found.
at AutoMapper.IMemberMap.get_UseDestinationValue()
at AutoMapper.Mappers.Internal.CollectionMapperExpressionFactory.<MapCollectionExpression>g__UseDestinationValue|1_0(<>c__DisplayClass1_0& )
at AutoMapper.Mappers.Internal.CollectionMapperExpressionFactory.MapCollectionExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap, IMemberMap memberMap, Expression sourceExpression, Expression destExpression, Expression contextExpression, Type ifInterfaceType, MapItem mapItem)
at AutoMapper.Mappers.CollectionMapper.MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap, IMemberMap memberMap, Expression sourceExpression, Expression destExpression, Expression contextExpression)
at AutoMapper.Execution.ExpressionBuilder.MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap, TypePair typePair, Expression sourceParameter, Expression contextParameter, IMemberMap propertyMap, Expression destinationParameter)
at AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc(IMemberMap memberMap, Expression destination, MemberInfo destinationMember)
at AutoMapper.Execution.TypeMapPlanBuilder.TryPropertyMap(PropertyMap propertyMap)
at AutoMapper.Execution.TypeMapPlanBuilder.CreateAssignmentFunc(Expression destinationFunc)
at AutoMapper.Execution.TypeMapPlanBuilder.CreateMapperLambda(HashSet`1 typeMapsPath)
at AutoMapper.TypeMap.Seal(IConfigurationProvider configurationProvider)
at AutoMapper.MapperConfiguration.Seal()
at AutoMapper.MapperConfiguration..ctor(MapperConfigurationExpression configurationExpression)
at AutoMapper.Mapper.Initialize(Action`1 config)
at OurService.Api.Startup.ConfigureServices(IServiceCollection services) in /data/workspace/our_service/src/OurService.Api/Startup.cs:line 198
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at OurService.Api.Program.Main(String[] args) in /data/workspace/our_service/src/OurService.Api/Program.cs:line 14
To Reproduce
We introduced automated instrumentation in the service like described here: https://docs.datadoghq.com/tracing/languages/dotnet/?tab=netcoreonlinux
During our e2e tests and on staging datadog is disabled using the env variable DD_TRACE_ENABLED=false on production it was enabled just by switching the flag DD_TRACE_ENABLED=true - this caused the error above.
The line in question was validating if the automapper configuration is correct Mapper.Configuration.AssertConfigurationIsValid();
The implementation of that function can be found here: https://github.com/AutoMapper/AutoMapper/blob/d9e9e7cbdfc46e4b762a9815f025ef20a52597fc/src/AutoMapper/Mapper.cs#L179
Expected behavior It should work with automapper
Runtime environment (please complete the following information):
- Instrumentation mode: automatic on .net core linux
- Tracer version: 0.8.2
- OS: linux in docker container
- CLR: .NET Core 2.2
Additional context
- Automapper version: 8.0.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 18 (8 by maintainers)
Just a heads up that I just finished up some other work and will start investigating this issue today. If it doesn’t make it in time for the 1.2 release in the next few days, we will follow up with a 1.2.1 for this issue.
@lucaspimentel - we could figure out that it happens when we define a mapping for generic collections such as
List<T>orDictionary, but it doesn’t happen for any other mappings. Funny enough, arrays, such asT[]work just fine.The error seems to happen in this line of automapper: https://github.com/AutoMapper/AutoMapper/blob/9903a3d2997c993e116c29d5f43c4ba89fac87d4/src/AutoMapper/Mappers/Internal/CollectionMapperExpressionFactory.cs#L65
unfortunately, we didn’t manage to reproduce it in an empty project yet. All that we could see, is, if we remove the mapping for those generic collection properties, it worked and if we put just one back, it breaks.
We’ll try to figure out, which other part of the application might influence those collections. In case you have any more ideas, how we could figure out, which assembly might affect the issue, we’re open for suggestions.
We are seeing the same issue with automapper 8.0.0 and dd-trace-dotnet 1.1.0. As soon as we disable tracing, it starts working.
We are using IdentityServer4.
This issue was fixed in .NET Core 2.1.12 and 2.2.6, which were released a few days ago. If your apps are running on these versions of .NET Core or newer, you can disable our workaround by setting environment variable
DD_CLR_DISABLE_OPTIMIZATIONS=false. (Linux only. The default is alreadyfalseon Windows.)As more users start using these newer versions of .NET Core, we will change the workaround so it is disabled by default. Users on older versions of .NET Core will still be able to opt-in by setting
DD_CLR_DISABLE_OPTIMIZATIONS=true.@moyuanhui this is going to be fixed in a future version of .net core 2.1 and 2.2.
We are facing the same issue using the .net core client 1.2.0 with Identity Server 4.
For Identity server it’s definitely to do with the EntityFrameworkCore -> AutoMapper integration (conflicting and throwing the same type of error as described above and in the provided example).
Additionally, I only need to add the APM package into docker and include ‘Datadog.Trace.ClrProfiler.Managed’ package into our project to start seeing the error. Setting the config
DD_TRACE_ENABLEDto true or false doesn’t influence the exception occurring.@lucaspimentel here you go with a repo reproducing the issue: https://github.com/pgrm/DD_EntryPointNotFoundException/
As I mentioned before, we still didn’t manage reproducing it starting from scratch, but now we took out pretty much everything from the broken project and the error is still happening. The README should detail all the findings, hope it will help to fix it. Thx