简体   繁体   中英

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation

My xamarin application run on emulator and also run on my device when I attached with my PC. But when I create its apk and then install it crash after splash scree. I track the log and try to identify but failed. Please help me to sort it out. The log is mention below:

10:44:37 E mono : Unhandled Exception:

10:44:37 E mono : System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: Could not load type System.Collections.Generic.KeyValuePair`2[[System.String, System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.String, System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]][], mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e while decoding custom attribute

10:44:37 E mono : at (wrapper managed-to-native) System.MonoCustomAttrs:GetCustomAttributesInternal (System.Reflection.ICustomAttributeProvider,System.Type,bool)

10:44:37 E mono : at System.MonoCustomAttrs.GetCustomAttributesBase (ICustomAttributeProvider obj, System.Type attributeType, Boolean inheritedOnly) [0x00019] in :0

10:44:37 E mono : at System.MonoCustomAttrs.GetCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType, Boolean inherit) [0x00040] in :0

10:44:37 E mono : at System.Reflection.MonoMethod.GetCustomAttributes (System.Type attributeType, Boolean inherit) [0x00000] in :0

10:44:37 E mono : at System.ServiceModel.Description.ContractDescriptionGenerator.GetOrCreateOperation (System.ServiceModel.Description.ContractDescription cd, System.Reflection.MethodInfo mi, System.Reflection.MethodInfo serviceMethod, System.ServiceModel.OperationContractAttribute oca, System.Reflection.MethodInfo endMethod, Boolean isCallback, System.Type givenServiceType) [0x0022d] in :0

10:44:37 E mono : at System.ServiceModel.Description.ContractDescriptionGenerator.FillOperationsForInterface (System.ServiceModel.Description.ContractDescription cd, System.Type exactContractType, System.Type givenServiceType, Boolean isCallback) [0x00134] in :0

10:44:37 E mono : at System.ServiceModel.Description.ContractDescriptionGenerator.GetContractInternal (System.Type givenContractType, System.Type givenServiceType, System.Type serviceTypeForCallback) [0x002d4] in :0

10:44:37 E mono : at System.ServiceModel.Description.ContractDescriptionGenerator.GetContract (System.Type givenContractType, System.Type givenServiceType, System.Type serviceTypeForCallback) [0x00000] in :0

10:44:37 E mono : at System.ServiceModel.Description.ContractDescriptionGenerator.GetContract (System.Type givenContractType, System.Type givenServiceType) [0x00000] in :0

10:44:37 E mono : at System.ServiceModel.Description.ContractDescriptionGenerator.GetContract (System.Type contractType) [0x00000] in :0

10:44:37 E mono : at System.ServiceModel.Description.ContractDescription.GetContract (System.Type contractType) [0x00017] in :0

10:44:37 E mono : at System.ServiceModel.ChannelFactory`1[TChannel].CreateDescription () [0x00000] in :0

10:44:37 E mono : at System.ServiceModel.ChannelFactory`1[TChannel]..ctor (System.Type type) [0x00033] in :0

10:44:37 E mono : at System.ServiceModel.ChannelFactory`1[TChannel]..ctor (System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in :0

10:44:37 E mono : at System.ServiceModel.ClientBase`1[TChannel].Initialize (System.ServiceModel.InstanceContext instance, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in :0

10:44:37 E mono : at System.ServiceModel.ClientBase`1[TChannel]..ctor (System.ServiceModel.InstanceContext instance, System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) [0x0003f] in :0

10:44:37 E mono : at System.ServiceModel.ClientBase`1[TChannel]..ctor (System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in :0

10:44:37 E mono : at AceVqbzServiceClient..ctor (System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in :0

10:44:37 E mono : at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)

10:44:37 E mono : at System.Refle

The application is crashing because some of code is remove at time of linking the assembly. So, you need to identify that code or remove if you can other wise the other option is to customize your linker according to your error log.

To run my apk, I skip/exclude three dll's from linking at the time create apk. ie System.Collection, System.Runtime, System.Runtime.Serialization. To do same just right click on your Droid project and go to properties and choose Android Option tab as you seen in below image: 在此处输入图片说明

Are you linking assemblies? Xamarin includes the functionality to link assemblies to reduce APK size, however not all assemblies seem to allow.

To confirm, I would change the debug settings to be identical to the release ones or to disable linking for the release. (Build > Droid Project Options)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM