admin管理员组文章数量:1406937
I use Automapper (v.14) in my .Net MAUI (v.9) app. I configure it as per documentation:
mauiAppBuilder.Services.AddAutoMapper(typeof(MappingProfile));
Then I am trying to resolve IMapper object in constructor of ViewModel
public MainPageViewModel(IMapper mapper)
Everything works fine on DEBUG. When I switch to Release, I get error:
[AndroidRuntime] android.runtime.JavaProxyThrowable: [System.Reflection.TargetInvocationException]: Arg_TargetInvocationException
[AndroidRuntime] at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs + 0x58(Unknown Source)
[AndroidRuntime] at System.RuntimeType.CreateInstanceMono + 0xa8(Unknown Source)
[AndroidRuntime] at System.RuntimeType.CreateInstanceOfT + 0x0(Unknown Source)
[AndroidRuntime] at System.Activator.CreateInstance + 0x18(Unknown Source)
[AndroidRuntime] at Microsoft.Extensions.Options.OptionsFactory`1[[AutoMapper.MapperConfigurationExpression, AutoMapper, Version=14.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005]].CreateInstance + 0x0(Unknown Source)
[AndroidRuntime] at Microsoft.Extensions.Options.OptionsFactory`1[[AutoMapper.MapperConfigurationExpression, AutoMapper, Version=14.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005]].Create + 0x0(Unknown Source)
[AndroidRuntime] at Microsoft.Extensions.Options.UnnamedOptionsManager`1[[AutoMapper.MapperConfigurationExpression, AutoMapper, Version=14.0.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005]].get_Value + 0x54(Unknown Source)
[AndroidRuntime] at Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions+<>c.<AddAutoMapperClasses>b__13_4 + 0x6(Unknown Source)
...
I found that it must be a linking problem because everything works fine when I disabled AOT and trimming on Release builds in .csproj
I tried Preserving Automapper Assembly but it didn't work, the exception still occured.
<ItemGroup>
<TrimmerRootAssembly Include="AutoMapper" RootMode="library" />
</ItemGroup>
Am I missing some important configuration, mixing concepts or something is broken either on maui or automapper side?
本文标签: TargetInvocationException when resolving IMapper on Android Release build in Net MAUIStack Overflow
版权声明:本文标题:TargetInvocationException when resolving IMapper on Android Release build in .Net MAUI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744972610a2635324.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论