gpt4 book ai didi

xamarin.ios - AutoMapper Mapper.Initialize 导致 System.Linq.Expressions (Xamarin.iOS) 中的 ArgumentNullException

转载 作者:行者123 更新时间:2023-12-01 13:30:05 25 4
gpt4 key购买 nike

我正在尝试将 AutoMapper 集成到我的 Xamarin Forms 应用程序中。它在 Android 设备和模拟器中都成功运行,但在 iOS 中我只能让它在模拟器中运行。在真实设备上运行它会导致 System.ArgumentNullException。

这是我的 App.xaml.cs OnStart 方法中的 Mapper.Initialize 代码:

// AutoMapper config
Mapper.Initialize(cfg =>
{
cfg.AddProfile<MappingProfile>();
});

这是堆栈跟踪:
System.ArgumentNullException: Value cannot be null.
Parameter name: method
at System.Linq.Expressions.Expression.Call (System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0) [0x0003e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.0.0.0/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/MethodCallExpression.cs:879
at AutoMapper.Mappers.ConvertMapper.ConvertExpression (System.Type sourceType, System.Type destinationType) [0x00040] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.Mappers.ConvertMapper+<>c__DisplayClass1_1.<GetConverters>b__4 () [0x00000] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at System.Lazy`1[T].CreateValue () [0x00081] in <6314851f133e4e74a2e96356deaa0c6c>:0
at System.Lazy`1[T].LazyInitValue () [0x0000c] in <6314851f133e4e74a2e96356deaa0c6c>:0
at System.Lazy`1[T].get_Value () [0x0003a] in <6314851f133e4e74a2e96356deaa0c6c>:0
at AutoMapper.Mappers.ConvertMapper.MapExpression (AutoMapper.IConfigurationProvider configurationProvider, AutoMapper.ProfileMap profileMap, AutoMapper.PropertyMap propertyMap, System.Linq.Expressions.Expression sourceExpression, System.Linq.Expressions.Expression destExpression, System.Linq.Expressions.Expression contextExpression) [0x00021] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.Execution.TypeMapPlanBuilder.ObjectMapperExpression (AutoMapper.IConfigurationProvider configurationProvider, AutoMapper.ProfileMap profileMap, AutoMapper.TypePair typePair, System.Linq.Expressions.Expression sourceParameter, System.Linq.Expressions.Expression contextParameter, AutoMapper.PropertyMap propertyMap, System.Linq.Expressions.Expression destinationParameter) [0x0000b] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.Execution.TypeMapPlanBuilder.MapExpression (AutoMapper.IConfigurationProvider configurationProvider, AutoMapper.ProfileMap profileMap, AutoMapper.TypePair typePair, System.Linq.Expressions.Expression sourceParameter, System.Linq.Expressions.Expression contextParameter, AutoMapper.PropertyMap propertyMap, System.Linq.Expressions.Expression destinationParameter) [0x0006d] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.Execution.TypeMapPlanBuilder.MapExpression (AutoMapper.TypePair typePair, System.Linq.Expressions.Expression sourceParameter, AutoMapper.PropertyMap propertyMap, System.Linq.Expressions.Expression destinationParameter) [0x00011] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc (AutoMapper.PropertyMap propertyMap, System.Linq.Expressions.Expression destination) [0x000de] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc (AutoMapper.PropertyMap propertyMap) [0x00000] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.Execution.TypeMapPlanBuilder.TryPropertyMap (AutoMapper.PropertyMap propertyMap) [0x00000] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.Execution.TypeMapPlanBuilder.CreateAssignmentFunc (System.Linq.Expressions.Expression destinationFunc, System.Boolean constructorMapping) [0x00044] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.Execution.TypeMapPlanBuilder.CreateMapperLambda (System.Collections.Generic.HashSet`1[T] visitedTypeMaps) [0x000bb] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.TypeMap.Seal (AutoMapper.IConfigurationProvider configurationProvider, System.Collections.Generic.HashSet`1[T] visitedTypeMaps) [0x00088] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.MapperConfiguration.Seal () [0x001f8] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.MapperConfiguration..ctor (AutoMapper.Configuration.MapperConfigurationExpression configurationExpression) [0x00177] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.MapperConfiguration..ctor (System.Action`1[T] configure) [0x00007] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at AutoMapper.Mapper.Initialize (System.Action`1[T] config) [0x00000] in <0cc4ddabcc77416ea712cf2d35abef51>:0
at Mobile.App.OnStart () [0x0002c]

我确保 Xcode、NuGet 包和 Visual Studio 都是最新的。

任何帮助表示赞赏!

最佳答案

答案是你需要包含一个 LinkDescription.xml 在项目的根目录中,build设置设置为 链接说明 以及以下内容:

<linker> 
<assembly fullname="mscorlib">
<type fullname="System.Convert" preserve="All" />
</assembly>
</linker>


边注:
我尝试将此行添加到附加 mtouch 参数 --linkskip System.Converthttps://docs.microsoft.com/en-us/xamarin/ios/deploy-test/linker 所述但它没有用。

只有 LinkDescription.xml 有效。可以在此处找到有关 LinkDescription.xml 如何工作的引用: https://docs.microsoft.com/en-us/learn/modules/prepare-to-publish-your-xamarin-application/5-preserve-critical-code

在 GitHub 上还有一个针对此问题的已关闭问题,它提出了相同的解决方案: https://github.com/AutoMapper/AutoMapper/issues/2272

关于xamarin.ios - AutoMapper Mapper.Initialize 导致 System.Linq.Expressions (Xamarin.iOS) 中的 ArgumentNullException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46394431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com