System.Reflection.TargetInvocationException:调用目标

时间:2015-12-24 10:20:20

标签: c# visual-studio-2013 xamarin xamarin.android apk

我的xamarin应用程序在模拟器上运行,并且当我连接到PC时也在我的设备上运行。但是当我创建它的apk然后安装它后飞溅scree崩溃。我跟踪日志并尝试识别但失败了。请帮我解决一下。日志如下:

  

10:44:37 E mono:未处理的异常:

     

10:44:37 E mono:System.Reflection.TargetInvocationException:   调用的目标抛出了异常。 --->   System.TypeLoadException:无法加载类型   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,版本= 2.0.5.0,文化=中性,   解码自定义属性

时,PublicKeyToken = 7cec85d7bea7798e      

10:44:37 E mono:at(包装托管到原生)   System.MonoCustomAttrs:GetCustomAttributesInternal   (System.Reflection.ICustomAttributeProvider,System.Type的,布尔)

     

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   继承)[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] ..构造函数   (System.ServiceModel.Channels.Binding绑定,   System.ServiceModel.EndpointAddress remoteAddress)[0x00000] in   :0

     

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

     

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

     

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

     

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

     

10:44:37 E mono:at(包装托管到原生)   System.Reflection.MonoCMethod:InternalInvoke   (System.Reflection.MonoCMethod,对象,对象[],System.Exception的&安培;)

     

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

2 个答案:

答案 0 :(得分:1)

应用程序崩溃,因为在链接程序集时删除了一些代码。因此,您需要识别该代码或删除,如果您可以根据您的错误日志另外选择自定义链接器

要运行我的apk,我在创建apk时跳过/排除链接中的三个dll。即 System.Collection,System.Runtime,System.Runtime.Serialization。要做到这一点,只需右键单击您的Droid项目,然后转到属性并选择Android Option选项卡,如下图所示: enter image description here

答案 1 :(得分:0)

您是否正在连接装配体? Xamarin包含链接程序集以减小APK大小的功能,但并非所有程序集似乎都允许。

要确认,我会将调试设置更改为与发布设置相同或禁用发布的链接。 (构建> Droid项目选项)