Mando
Mando

Reputation: 11712

InvalidProgramException during MvvmCross Setup instance initialization

I'm using the MvvmCross framework to deliver cross-platform app using Xamarin. My Windows Phone application works absolutely file under the WP8 platform and fails with internal error under the WP7 platform. I'm using the single visual studio project (WP7 template) for both WP7 and WP8 platforms.

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

And here the detailed 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)

Any ideas how to diagnose and fix the issue?

Upvotes: 0

Views: 140

Answers (1)

Stuart
Stuart

Reputation: 66882

Any ideas how to diagnose and fix the issue?

The Cirrious.CrossCore.Platform.MvxBootstrapRunner.Run call is looking over your main assembly and looking for bootstrap classes to run.

The exception is occurring during that sweep.

You should be able to get a bit more info about the exception by turning on "break on exceptions" for InvalidProgramException

Failing that, you could also cause the exception in your own code using a modified CreatableTypes call - i.e. in your Setup code override PerformBootstrapActions and try calling:

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

with:

    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;
                });
    }

This will hopefully help you diagnose what is failing... then the fix will hopefully follow.


Aside: Please also note that v3.1 of MvvmCross (and later) will not support WP7 because Microsoft have only licensed newer PCL libraries for cross-platform use - see http://slodge.blogspot.co.uk/2013/07/mvvmcross-wp7-tombstoned.html. v3.0.14 is the last official MvvmCross support for WP7

Upvotes: 1

Related Questions