【问题标题】:InvalidProgramException during MvvmCross Setup instance initializationMvvmCross Setup 实例初始化期间的 InvalidProgramException
【发布时间】:2014-01-29 14:11:27
【问题描述】:

我正在使用 MvvmCross 框架来交付使用 Xamarin 的跨平台应用程序。 我的 Windows Phone 应用程序在 WP8 平台下完全可以正常工作,在 WP7 平台下失败并出现内部错误。我正在为 WP7 和 WP8 平台使用单个 Visual Studio 项目(WP7 模板)。

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

这里是详细的堆栈跟踪:

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)

对如何诊断和解决问题有任何想法吗?

【问题讨论】:

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


    【解决方案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 支持

    【讨论】:

    • 我不知道 WP7,是的,我使用的是最新的 MvvmCross 版本,所以这就是问题所在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多