调用ShowViewModel时出错

时间:2017-06-26 15:53:06

标签: mvvmcross

在我有一个项目列表的地方编写示例应用程序,然后当用户点击某个项目时 - 它使用ShowViewModel显示有关该项目的详细信息页面。但是,当调用调用ShowViewModel的方法时,它会崩溃并出现以下错误: “无法使用令牌01000037解析类型 (来自typeref,类/汇编MvvmCross.Core.ViewModels.MvxRequestedBy ......“

示例应用的代码在这里: https://github.com/gregmercer/FruitsAndVeggies

完整的错误消息在这里: https://github.com/gregmercer/FruitsAndVeggies/blob/master/error.txt

在此处找到导致错误的行(取消注释时): https://github.com/gregmercer/FruitsAndVeggies/blob/master/FruitsAndVeggies.Core/ViewModels/FruitsViewModel.cs#L58

2 个答案:

答案 0 :(得分:2)

问题是你正在混合使用MvvmCross版本。

因此,如果你看看你的core.config为你的核心:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="MvvmCross" version="4.4.0" targetFramework="portable45-net45+win8+wpa81" />
  <package id="MvvmCross.Binding" version="4.4.0" targetFramework="portable45-net45+win8+wpa81" />
  <package id="MvvmCross.Core" version="4.4.0" targetFramework="portable45-net45+win8+wpa81" />
  <package id="MvvmCross.Platform" version="4.4.0" targetFramework="portable45-net45+win8+wpa81" />
</packages>

这些是版本4.4.0

然后,如果我们看看Droid项目:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="MvvmCross" version="5.0.2" targetFramework="monoandroid70" />
  <package id="MvvmCross.Binding" version="5.0.2" targetFramework="monoandroid70" />
  <package id="MvvmCross.Core" version="5.0.2" targetFramework="monoandroid70" />
  <package id="MvvmCross.Droid.Shared" version="5.0.2" targetFramework="monoandroid70" />
  <package id="MvvmCross.Droid.Support.Core.UI" version="5.0.2" targetFramework="monoandroid70" />
  <package id="MvvmCross.Droid.Support.Fragment" version="5.0.2" targetFramework="monoandroid70" />
  <package id="MvvmCross.Droid.Support.V7.AppCompat" version="5.0.2" targetFramework="monoandroid70" />
  <package id="MvvmCross.Droid.Support.V7.RecyclerView" version="5.0.2" targetFramework="monoandroid70" />
  <package id="MvvmCross.Platform" version="5.0.2" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Annotations" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Compat" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Core.UI" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Core.Utils" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Design" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Fragment" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Media.Compat" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Transition" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.v7.RecyclerView" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Vector.Drawable" version="25.3.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Build.Download" version="0.4.3" targetFramework="monoandroid70" />
</packages>

这些是版本5.0.2,比4.4.0更新。

合并您的软件包并在所有项目中使用相同的版本。

答案 1 :(得分:-1)

要传递参数,您需要从通用MvxViewModel< Parameters>继承或更新到MvvmCross 5.0,这样可以更好地支持传递对象。

将此示例视为参考:https://github.com/MvvmCross/MvvmCross/tree/develop/TestProjects/Navigation