MvvmCross安装实例初始化期间出现InvalidProgramException

时间:2014-01-29 04:45:49

标签: windows-phone-7 cross-platform xamarin mvvmcross invalidprogramexception

我使用MvvmCross框架使用Xamarin提供跨平台应用程序。 我的Windows Phone应用程序在WP8平台下运行绝对文件,并在WP7平台下失败并出现内部错误。我在WP7和WP8平台上使用单一的visual studio项目(WP7模板)。

var setup = new Setup(RootFrame);
setup.Initialize();

这里有详细的stacktrace:

System.InvalidProgramException was unhandled
  Message=InvalidProgramException
  StackTrace:
       at System.RuntimeType.GetConstructors(BindingFlags bindingAttr)
       at Cirrious.CrossCore.IoC.MvxTypeExtensions.<CreatableTypes>b__1(Type t)
       at System.Linq.Enumerable.<WhereIterator>d__0`1.MoveNext()
       at System.Linq.Enumerable.<WhereIterator>d__0`1.MoveNext()
       at Cirrious.CrossCore.Platform.MvxBootstrapRunner.Run(Assembly assembly)
       at Cirrious.MvvmCross.Platform.MvxSetup.PerformBootstrapActions()
       at Cirrious.MvvmCross.Platform.MvxSetup.InitializeSecondary()
       at Cirrious.MvvmCross.Platform.MvxSetup.Initialize()
       at MyApp.WP.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)

如何诊断和解决问题?

1 个答案:

答案 0 :(得分:1)

  

如何诊断和解决问题?

Cirrious.CrossCore.Platform.MvxBootstrapRunner.Run调用正在查看主程序集并查找要运行的引导类。

扫描期间发生异常。

您应该可以通过启用InvalidProgramException

的“例外中断”来获取有关该例外的更多信息

如果失败,您也可以使用经过修改的CreatableTypes调用在您自己的代码中引发异常 - 即在Setup代码覆盖PerformBootstrapActions并尝试调用:

    var things = MyCreatableTypes(this.GetType().Assembly).ToList();

使用:

    public IEnumerable<Type> MyCreatableTypes(Assembly assembly)
    {
        return assembly
            .ExceptionSafeGetTypes()
            .Where(t => !t.IsAbstract)
            .Where(t => {
                try
                {
                    Mvx.Trace("About to call GetConstructors for Type {0}", t.Name);
                    return t.GetConstructors(BindingFlags.Instance | BindingFlags.Public).Any()
                }
                catch (InvalidProgramException e)
                {
                    // your trace or debugging code...
                    return false;
                });
    }

这有望帮助您诊断失败的内容......然后修复将会有所帮助。


旁白:还请注意,MvvmCross(及更高版本)的v3.1将不支持WP7,因为Microsoft仅授权更新的PCL库用于跨平台使用 - 请参阅http://slodge.blogspot.co.uk/2013/07/mvvmcross-wp7-tombstoned.html。 v3.0.14是对WP7的最后一次官方MvvmCross支持