【问题标题】:TargetInvocationException when running project on wp7在 wp7 上运行项目时出现 TargetInvocationException
【发布时间】:2014-05-22 22:02:07
【问题描述】:

我有一个大型 wp7 项目,在 wp7 上运行良好。在过去的几个星期里,我使用 wp8 设备进行调试(项目仍然是 wp7),它很好。

现在,我开始在 wp7 设备上对其进行测试,结果让我陷入了困境

System.Windows.Application.LoadComponent(this, new System.Uri("/MyApp;component/App.xaml", System.UriKind.Relative));

这个异常

System.Reflection.TargetInvocationException occurred
  Message=TargetInvocationException
  StackTrace:
       at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
       at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
       at MS.Internal.TypeProxy.<>c__DisplayClass30.<GetCreateObjectDelegate>b__2a()
       at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId)
       at MS.Internal.XamlManagedRuntimeRPInvokes.CreateInstance(XamlTypeToken inXamlType, XamlQualifiedObject& newObject)
       at MS.Internal.XcpImports.Application_LoadComponentNative(IntPtr pContext, IntPtr pComponent, UInt32 cUriStringLength, String uriString, UInt32 cXamlStrLength, Byte* pXamlStr, UInt32 cAssemblyStrLength, String assemblyStr)
       at MS.Internal.XcpImports.Application_LoadComponent(IManagedPeerBase componentAsDO, String resourceLocator, UnmanagedMemoryStream stream, UInt32 numBytesToRead, String assemblyString)
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at MyApp.App.InitializeComponent()
       at MyApp.App..ctor()
       at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
       at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
       at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
       at MS.Internal.TypeProxy.<>c__DisplayClass30.<GetCreateObjectDelegate>b__2a()
       at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId)
       at MS.Internal.FrameworkCallbacks.CreateKnownObject(IntPtr nativeRootPeer, UInt32 customTypeId, String initializationString, IntPtr& nativePeer, UInt32 isCreatedByParser)
       at MS.Internal.FrameworkCallbacks.CreateUnknownObject(String assemblyName, String typeName, IntPtr nativeRootPeer, String initializationString, UInt32& customTypeId, UInt32& coreTypeId, UInt32& typeFlags, IntPtr& nativePeer)
  InnerException: System.MissingMethodException
       Message=Could not load type 'System.Func`2' from assembly 'mscorlib, Version=3.7.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC'.

我改变了很多东西,所以我不知道去哪里找。

关于什么可能是原因的任何建议? System.Func'2 是什么?

编辑:再次澄清一下:项目始终针对 wp7。目前是:

EDIT2:输出为:

'TaskHost.exe' (Managed): Loaded 'System.Device.dll' 
'TaskHost.exe' (Managed): Loaded 'Cimbalino.Phone.Toolkit.Background.dll'
'TaskHost.exe' (Managed): Loaded 'Cimbalino.Phone.Toolkit.dll'
'TaskHost.exe' (Managed): Loaded 'GalaSoft.MvvmLight.Extras.WP71.dll'
'TaskHost.exe' (Managed): Loaded 'System.Runtime.Serialization.dll'

也许有帮助? wp7上的Serialization.dll有问题吗?

EDIT3:我的系统配置:Windows 8.1 Pro、MSVS Pro 2012 Update 4。

【问题讨论】:

  • 您无法在 WP7 上运行针对 WP8 的应用程序。您要么必须有两个针对 WP7 和 WP8 的单独项目,要么保留针对 WP7 的项目,这样两个操作系统都可以运行应用程序。
  • 是wp7应用程序。刚刚编辑了问题以澄清这一点。
  • 所以你把它定位到 WP8 并改回 WP7?
  • @CamBruce 不,我只是使用 WP8 设备进行测试。它是/一直是 wp7 项目。
  • 如果您只是通过 wp7 应用程序进行部署,请尝试完全卸载该应用程序,在 VS 中运行“干净的解决方案”,然后重新部署。

标签: c# windows-phone-7 exception windows-phone-8


【解决方案1】:

好的,我已经设法解决了这个问题。问题在于 Newtonsoft.Json 库,当前版本(6.0.3)声称与 wp7 兼容,但实际上并非如此。

解决方案:只需回滚到 5.0.8: Install-Package Newtonsoft.Json -Version 5.0.8

【讨论】:

  • 因此,这是您项目的内部问题,与使用 wp8 wp7 设备和任何项目目标更改无关。好吧,太好了:)
  • @GauravDeochakke 是的 :) 但是,我遇到了另一个问题:服务器调用在 wp8 上运行良好,并在 wp7 上引发 NotFound 异常:stackoverflow.com/questions/23816912/network-errors-on-wp7
【解决方案2】:

一旦您在 VS 2012 中使用带有 WP8 目标平台的 WP SDK 8.0 打开您的 WP7 应用程序,您就不能再将此项目用作 WP7 项目。如果您想在 VS 2012 的新环境中继续开发,您需要使用 Target 平台:WP 7.1。 请检查目标平台设置的内容。

如果你想支持WP 7 OS,你需要维护两个不同的应用程序并独立提交到商店。 因此,您似乎使用 vs2012 和 sdk 8.0 打开了项目,然后在 wp8 上构建并运行它,然后再次尝试为 wp7 设备执行此操作。 就是这样,我认为应该是问题。

【讨论】:

  • 感谢您的回答。但是该项目 wp7 导向的。我更新了问题。通常,我提交了一个 wp7 项目,它适用于 wp7 和 wp8。
  • 您能否澄清一下“上次,我开发它时仅使用 wp8 设备进行调试(项目仍用于 wp7)。”你的这个声明?这让我想错了方向。
  • 是的,对不起 - 看起来我以一种非常奇怪的方式制定了它。我的意思是我使用 wp8 设备来测试 wp7 项目,这很好。现在我正在使用 wp7 设备测试同一个 wp7 项目,但它抛出了一个异常。
  • 你用的是什么版本的visual studio和windows?
  • Windows 8.1 Pro,使用 MSVS Pro 2012,更新 4。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-07
  • 2015-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-05
相关资源
最近更新 更多