【问题标题】:System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocationSystem.Reflection.TargetInvocationException:调用的目标已引发异常
【发布时间】:2016-03-30 19:18:53
【问题描述】:

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

10:44:37 E 单声道:未处理的异常:

10:44:37 E 单声道:System.Reflection.TargetInvocationException: 调用的目标已引发异常。 ---> System.TypeLoadException:无法加载类型 System.Collections.Generic.KeyValuePair`2[[System.String, System.Runtime,版本=4.0.0.0,文化=中性, PublicKeyToken=b03f5f7f11d50a3a],[System.String, System.Runtime, 版本=4.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a]][], mscorlib,版本=2.0.5.0,文化=中性, PublicKeyToken=7cec85d7bea7798e 解码自定义属性时

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

10:44:37 E 单声道:在 System.MonoCustomAttrs.GetCustomAttributesBase (ICustomAttributeProvider obj, System.Type attributeType, Boolean hiddenOnly) [0x00019] in :0

10:44:37 E 单声道:在 System.MonoCustomAttrs.GetCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType, Boolean 继承)[0x00040] in :0

10:44:37 E 单声道:在 System.Reflection.MonoMethod.GetCustomAttributes (System.Type attributeType, Boolean 继承) [0x00000] in :0

10:44:37 E 单声道:在 System.ServiceModel.Description.ContractDescriptionGenerator.GetOrCreateOperation (System.ServiceModel.Description.ContractDescription 光盘, 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 单声道:在 System.ServiceModel.Description.ContractDescriptionGenerator.FillOperationsForInterface (System.ServiceModel.Description.ContractDescription 光盘,System.Type exactContractType, System.Type givenServiceType, Boolean isCallback) [0x00134] 在:0

10:44:37 E 单声道:在 System.ServiceModel.Description.ContractDescriptionGenerator.GetContractInternal (System.Type givenContractType, System.Type givenServiceType, System.Type serviceTypeForCallback) [0x002d4] in :0

10:44:37 E 单声道:在 System.ServiceModel.Description.ContractDescriptionGenerator.GetContract (System.Type givenContractType, System.Type givenServiceType, System.Type serviceTypeForCallback) [0x00000] in :0

10:44:37 E 单声道:在 System.ServiceModel.Description.ContractDescriptionGenerator.GetContract (System.Type givenContractType, System.Type givenServiceType) [0x00000] 在 :0

10:44:37 E 单声道:在 System.ServiceModel.Description.ContractDescriptionGenerator.GetContract (System.Type contractType) [0x00000] in :0

10:44:37 E 单声道:在 System.ServiceModel.Description.ContractDescription.GetContract (System.Type contractType) [0x00017] in :0

10:44:37 E 单声道:在 System.ServiceModel.ChannelFactory`1[TChannel].CreateDescription() [0x00000] 在 :0

10:44:37 E 单声道:在 System.ServiceModel.ChannelFactory`1[TChannel]..ctor (System.Type 类型)[0x00033] in :0

10:44:37 E 单声道:在 System.ServiceModel.ChannelFactory`1[TChannel]..ctor (System.ServiceModel.Channels.Binding 绑定, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] 在 :0

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

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

10:44:37 E 单声道:在 System.ServiceModel.ClientBase`1[TChannel]..ctor (System.ServiceModel.Channels.Binding 绑定, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] 在 :0

10:44:37 E 单声道:在 AceVqbzServiceClient..ctor (System.ServiceModel.Channels.Binding 绑定, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] 在 :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 单声道:在 System.Refle

【问题讨论】:

  • 您需要添加对 system.runtime 版本 4.0.0.0 的引用它无法加载它
  • 在我的视觉工作室中,它显示它已经被添加。即使我删除了这些引用,我的项目仍然在模拟器中运行并且没有给出任何错误
  • 您需要启用融合日志,它将为您提供有关未加载哪个程序集的更多信息。还要检查 bin 文件夹中的所有程序集都有哪些
  • 不,但是 System.Runtime.Serialization.dll 在这里显示为红色
  • 请启用融合日志这是一个非常简单的问题

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


【解决方案1】:

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

为了运行我的 apk,我在创建 apk 时跳过/排除了链接中的三个 dll。即 System.Collection、System.Runtime、System.Runtime.Serialization。 只需右键单击您的 Droid 项目并转到属性并选择 Android 选项选项卡,如下图所示:

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 是的,我知道。我尝试将链接设置为无,但仍然出现相同的错误。
    • @AjaySharma 我建议您将问题重命名为“System.TypeLoadException:无法加载类型 System.Collections.Generic.KeyValuePair”,因为这是您的例外,而且尝试使用堆栈跟踪也很划算在这些情况下
    • @Virgil "Stack Trace" 能在这方面做什么帮助?
    猜你喜欢
    • 1970-01-01
    • 2019-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-09
    • 1970-01-01
    相关资源
    最近更新 更多