Hi, my android application sometimes stucks on startup. On Xamarin test cloud the failure seems like;
SetUp : System.TimeoutException : Timed out waiting...
at Xamarin.UITest.Shared.WaitForHelper.WaitFor (System.Func1 predicate, System.String timeoutMessage, Nullable1 timeout, Nullable1 retryFrequency, Nullable1 postTimeout) <0x7e4c998 + 0x004db> in :0
at Xamarin.UITest.Android.AndroidApp..ctor (IAndroidAppConfiguration appConfiguration) <0x7cacab8 + 0x0073b> in :0
at Xamarin.UITest.Configuration.AndroidAppConfigurator.StartApp (AppDataMode appDataMode) <0x7cac008 + 0x00063> in :0
at YH.MB.Test.AppInitializer.StartApp (Platform platform) <0x7cab060 + 0x00027> in :0
at YH.MB.Test.Tests.BeforeEachTest () <0x7cab010 + 0x00013> in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x3249110 + 0x00093> in :0
When i tried it on Samsung s3(on xamarin test cloud) there was a StackTrace too;
java.lang.NullPointerException: key == null
at android.util.LruCache.get(LruCache.java: 113)
at com.android.providers.settings.SettingsProvider$SettingsCache.isRedundantSetValue(SettingsProvider.java: 872)
at com.android.providers.settings.SettingsProvider.insert(SettingsProvider.java: 574)
at android.content.ContentProvider$Transport.insert(ContentProvider.java: 201)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java: 148)
at android.os.Binder.execTransact(Binder.java: 367)
at dalvik.system.NativeStart.run(Native Method: )
I can not repeat that issue on debug mode. What can it be?
My Android OnCreate method is;
protected override void OnCreate(Bundle bundle)
{
// set the layout resources first
ToolbarResource = Resource.Layout.toolbar;
TabLayoutResource = Resource.Layout.tabs;
base.OnCreate(bundle);
Forms.Init(this, bundle);
#if ENABLE_TEST_CLOUD
Xamarin.Forms.Forms.ViewInitialized += (object sender, Xamarin.Forms.ViewInitializedEventArgs e) =>
{
if (!string.IsNullOrWhiteSpace(e.View.AutomationId))
{
e.NativeView.ContentDescription = e.View.AutomationId;
}
};
#endif
var container = new SimpleContainer();
container.Register<IDevice>(t => AndroidDevice.CurrentDevice);
container.Register<IDisplay>(t => t.Resolve<IDevice>().Display);
container.Register<IMediaPicker>(t => new MediaPicker());
container.Register<IFontManager>(t => new FontManager(t.Resolve<IDisplay>()));
container.Register<INetwork>(t => t.Resolve<IDevice>().Network);
container.Register<IJsonSerializer, MBJsonSerializer>();
container.Register<IPhoneService, PhoneService>();
container.Register<IUserDialogs>(t => UserDialogs.Instance);
if (!Resolver.IsSet)
Resolver.SetResolver(container.GetResolver());
UserDialogs.Init(this);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
My UITest SetUp Method ;
[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]
public class Tests
{
IApp app;
Platform platform;
public Tests(Platform platform)
{
this.platform = platform;
}
[SetUp]
public void BeforeEachTest()
{
app = AppInitializer.StartApp(platform);
}
}
Thanks in advance.
Related
I'm having trouble with registering a platform specific service (iOS). This used to work fine, but now when running the app I get the following exception:
DryIoc.ContainerException: code: Error.UnableToResolveUnknownService;
message: Unable to resolve resolution root PS.Forms.VoiceApp.Base.Interfaces.IInitService
from container with scope {Name=null}
with Rules with {TrackingDisposableTransients, UseDynamicRegistrationsAsFallbackOnly, FuncAndLazyWithoutRegistration, SelectLastRegisteredFactory} and without {ThrowOnRegisteringDisposableTransient, UseFastExpressionCompilerIfPlatformSupported}
with FactorySelector=SelectLastRegisteredFactory
with Made={FactoryMethod=ConstructorWithResolvableArguments}
Where no service registrations found
and no dynamic registrations found in 1 of Rules.DynamicServiceProviders
and nothing found in 0 of Rules.UnknownServiceResolvers
at DryIoc.Throw.It (System.Int32 error, System.Object arg0, System.Object arg1, System.Object arg2, System.Object arg3) [0x00000] in /_/src/DryIoc/Container.cs:13642
at DryIoc.Container.TryThrowUnableToResolve (DryIoc.Request request) [0x0006d] in /_/src/DryIoc/Container.cs:1088
at DryIoc.Container.DryIoc.IContainer.ResolveFactory (DryIoc.Request request) [0x00072] in /_/src/DryIoc/Container.cs:1068
at DryIoc.Container.ResolveAndCache (System.Int32 serviceTypeHash, System.Type serviceType, DryIoc.IfUnresolved ifUnresolved) [0x00021] in /_/src/DryIoc/Container.cs:367
at DryIoc.Container.DryIoc.IResolver.Resolve (System.Type serviceType, DryIoc.IfUnresolved ifUnresolved) [0x0011c] in /_/src/DryIoc/Container.cs:356
at DryIoc.Container.DryIoc.IResolver.Resolve (System.Type serviceType, System.Object serviceKey, DryIoc.IfUnresolved ifUnresolved, System.Type requiredServiceType, DryIoc.Request preResolveParent, System.Object[] args) [0x00039] in /_/src/DryIoc/Container.cs:428
at DryIoc.Resolver.Resolve (DryIoc.IResolver resolver, System.Type serviceType, System.Object[] args, DryIoc.IfUnresolved ifUnresolved, System.Type requiredServiceType, System.Object serviceKey) [0x00000] in /_/src/DryIoc/Container.cs:8087
at Prism.DryIoc.DryIocContainerExtension.Resolve (System.Type type, System.ValueTuple`2[System.Type,System.Object][] parameters) [0x0001c] in /_/src/Containers/Prism.DryIoc.Shared/DryIocContainerExtension.cs:294
I don't know why this would happen all of a sudden. In my AppDelegate.cs I register the IOSInitService which implements the Interface IInitService like this:
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) {
this.PreventLinkerFromStrippingCommonLocalizationReferences();
Rg.Plugins.Popup.Popup.Init();
this.ShinyFinishedLaunching(new VoiceAppStartup {
RegisterPlatformServices = services =>
{
services.AddSingleton<IInitService, IOSInitService>();
}
});
global::Xamarin.Forms.Forms.Init();
FormsControls.Touch.Main.Init();
this.LoadApplication(new App());
return base.FinishedLaunching(application, launchOptions);
}
I also register some other services in the App.xaml (which I can't do here with platform specific implementations) an they work fine:
protected override void RegisterTypes(IContainerRegistry containerRegistry) {
containerRegistry.RegisterPopupNavigationService();
containerRegistry.RegisterSingleton<IAppInfo, AppInfoImplementation>();
containerRegistry.RegisterSingleton<IShare, ShareImplementation>();
...}
Does anybody have an idea why that could be? The exception implies, that the service is not registered or am I missing something?
I have a ASP.NET 5 / Core RC1 MVC(WebApi) application that is interfacing with auth0 for Bearer authentication using JWT tokens. The application uses dnx451 as the framework (not CoreCLR because of unsupported dependencies).
When running the application on Windows, it works perfectly fine.
However I would like to run it on Ubuntu using Mono as runtime for dnx451. There, the app runs but as soon as I make a request to it, it returns with Internal Server Error 500.
The log output:
info: Microsoft.AspNet.Hosting.Internal.HostingEngine[3]
Request finished in 0.0006ms 500
fail: Microsoft.AspNet.Server.Kestrel[13]
An unhandled exception was thrown by the application.
System.IdentityModel.Tokens.SecurityTokenInvalidSignatureException: IDX10503: Signature validation failed. Keys tried: 'System.IdentityModel.Tokens.X509SecurityKey , KeyId: MTZBREFEQ0M5NUQ2RDY3RDkzM0E0RDYwMDdCM0I4QUY1MDc3RUNDNA
'.
Exceptions caught:
'System.TypeLoadException: Could not load type 'System.IdentityModel.Tokens.AsymmetricSignatureProvider' from assembly 'System.IdentityModel.Tokens, Version=5.0.0.112, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at System.IdentityModel.Tokens.SignatureProviderFactory.CreateForVerifying (System.IdentityModel.Tokens.SecurityKey key, System.String algorithm) <0x4067def0 + 0x0001b> in <filename unknown>:0
at System.IdentityModel.Tokens.X509SecurityKey.GetSignatureProvider (System.String algorithm, Boolean verifyOnly) <0x4067de30 + 0x00057> in <filename unknown>:0
at System.IdentityModel.Tokens.SecurityKey.GetSignatureProviderForValidating (System.String algorithm) <0x4067de00 + 0x0001a> in <filename unknown>:0
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature (System.Byte[] encodedBytes, System.Byte[] signature, System.IdentityModel.Tokens.SecurityKey key, System.String algorithm) <0x4067dcb0 + 0x0003f> in <filename unknown>:0
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature (System.String token, System.IdentityModel.Tokens.TokenValidationParameters validationParameters) <0x40679070 + 0x004b3> in <filename unknown>:0
'.
token: '{"alg":"RS256","typ":"JWT","kid":"MTZBREFEQ0M5NUQ2RDY3RDkzM0E0RDYwMDdCM0I4QUY1MDc3RUNDNA"}.{"iss":"**********","sub":"*****************","aud":"****************","exp":1464737848,"iat":1464701848}'
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature (System.String token, System.IdentityModel.Tokens.TokenValidationParameters validationParameters) <0x40679070 + 0x0096b> in <filename unknown>:0
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken (System.String token, System.IdentityModel.Tokens.TokenValidationParameters validationParameters, System.IdentityModel.Tokens.SecurityToken& validatedToken) <0x406782f0 + 0x0021d> in <filename unknown>:0
at Microsoft.AspNet.Authentication.JwtBearer.JwtBearerHandler+<HandleAuthenticateAsync>d__1.MoveNext () <0x41f5bcf0 + 0x011c4> in <filename unknown>:0
Is this a general incompatibility with Mono/ASP.NET 5 or is there anything to do about it ?
The problem only occurs because AsymmetricSignatureProvider has windows marshalling and is loaded even if you are using a SymmetricSecurityKey. If you are happy to use a SymmetricSecurityKey here is a workaround:
signingKey.CryptoProviderFactory = new MonoFriendlyCryptoProviderFactory(_LoggerFactory.CreateLogger<MonoFriendlyCryptoProviderFactory>());
public class MonoFriendlyCryptoProviderFactory : CryptoProviderFactory
{
private readonly ILogger _Logger;
public MonoFriendlyCryptoProviderFactory(ILogger logger)
{
_Logger = logger;
}
public override SignatureProvider CreateForSigning(SecurityKey key, string algorithm)
{
return CreateProvider(key, algorithm, true);
}
public override SignatureProvider CreateForVerifying(SecurityKey key, string algorithm)
{
return CreateProvider(key, algorithm, false);
}
private SignatureProvider CreateProvider(SecurityKey key, string algorithm, bool willCreateSignatures)
{
_Logger?.LogDebug($"Creating {algorithm} provider for {key.KeyId} for {(willCreateSignatures ? "signing" : "verifying")}");
if (key == null)
throw new ArgumentNullException(nameof(key));
if (string.IsNullOrWhiteSpace(algorithm))
throw new ArgumentNullException(nameof(algorithm));
//AsymmetricSecurityKey asymmetricSecurityKey = key as AsymmetricSecurityKey;
//if (asymmetricSecurityKey != null)
// return new AsymmetricSignatureProvider(asymmetricSecurityKey, algorithm, willCreateSignatures, this.AsymmetricAlgorithmResolver);
SymmetricSecurityKey symmetricSecurityKey = key as SymmetricSecurityKey;
if (symmetricSecurityKey != null)
return new SymmetricSignatureProvider(symmetricSecurityKey, algorithm);
JsonWebKey jsonWebKey = key as JsonWebKey;
if (jsonWebKey != null && jsonWebKey.Kty != null)
{
//if (jsonWebKey.Kty == "RSA" || jsonWebKey.Kty == "EC")
// return new AsymmetricSignatureProvider(key, algorithm, willCreateSignatures, this.AsymmetricAlgorithmResolver);
if (jsonWebKey.Kty == "oct")
return new SymmetricSignatureProvider(key, algorithm);
}
throw new ArgumentException($"{typeof(SignatureProvider)} supports: '{typeof(SecurityKey)}' of types: '{typeof(AsymmetricSecurityKey)}' or '{typeof(AsymmetricSecurityKey)}'. SecurityKey received was of type: '{key.GetType()}'.");
}
}
This is identical to the rc2 build of Microsoft.IdentityModel.Tokens except for the commented out sections which have no function if you are not using a AsymmetricSecurityKey.
net45x is the only option since dnx has been dropped and various drivers will not target coreclr for many months yet.
After updating my project to Unified API and MVVM Cross 3.5 stable ,I am getting the following warring message in the console for all button bindings...
I am binding like this.
try {
this.AddBindings(
new Dictionary < object, string > () {
//all the command controls - such as buttons
{
btnXmit,
"TouchUpInside cmdXmitClicked"
}, {
btnCancel,
"TouchUpInside cmdBack"
},
});
} catch (Exception error) {
}
at
Cirrious.CrossCore.WeakSubscription.MvxWeakEventSubscription2[System.Windows.Input.ICommand,System.EventArgs]..ctor (ICommand source, System.Reflection.EventInfo sourceEventInfo, System.EventHandler1 targetEventHandler) [0x00028] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakEventSubscription.cs:52
at Cirrious.CrossCore.WeakSubscription.MvxCanExecuteChangedEventSubscription..ctor (ICommand source, System.EventHandler1 eventHandler) [0x00000] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxCanExecuteChangedEventSubscription.cs:21
at Cirrious.CrossCore.WeakSubscription.MvxWeakSubscriptionExtensionMethods.WeakSubscribe (ICommand source, System.EventHandler1 eventHandler) [0x00003] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakSubscriptionExtensionMethods.cs:68
at Cirrious.MvvmCross.Binding.Touch.Target.MvxUIControlTouchUpInsideTargetBinding.SetValueImpl (System.Object target, System.Object value) [0x00045] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Target/MvxUIControlTouchUpInsideTargetBinding.cs:74
at Cirrious.MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x000bd] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding/Bindings/Target/MvxConvertingTargetBinding.cs:64
at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00036] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding/Bindings/MvxFullBinding.cs:162
2015-02-16 17:48:14.433 RemoteInspectioniOS[3506:119564] MvxBind: Error: 212.37 Problem seen during binding execution for binding TouchUpInside for cmdBack - problem ArgumentNullException: missing source event info in MvxWeakEventSubscription
Parameter name: sourceEventInfo
at Cirrious.CrossCore.WeakSubscription.MvxWeakEventSubscription2[System.Windows.Input.ICommand,System.EventArgs]..ctor (ICommand source, System.Reflection.EventInfo sourceEventInfo, System.EventHandler1 targetEventHandler) [0x00028] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakEventSubscription.cs:52
at Cirrious.CrossCore.WeakSubscription.MvxCanExecuteChangedEventSubscription..ctor (ICommand source, System.EventHandler1 eventHandler) [0x00000] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxCanExecuteChangedEventSubscription.cs:21
at Cirrious.CrossCore.WeakSubscription.MvxWeakSubscriptionExtensionMethods.WeakSubscribe (ICommand source, System.EventHandler1 eventHandler) [0x00003] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakSubscriptionExtensionMethods.cs:68
at Cirrious.MvvmCross.Binding.Touch.Target.MvxUIControlTouchUpInsideTargetBinding.SetValueImpl (System.Object target, System.Object value) [0x00045] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Target/MvxUIControlTouchUpInsideTargetBinding.cs:74
at Cirrious.MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x000bd] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding/Bindings/Target/MvxConvertingTargetBinding.cs:64
at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00036] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding/Bindings/MvxFullBinding.cs:162
You'll need to create a LinkerPleaseInclude.cs file with the following code:
public class LinkerPleaseInclude
{
public void Include(ICommand command)
{
command.CanExecuteChanged += (s, e) => { if (command.CanExecute(null)) command.Execute(null); };
}
}
EDIT (per my comment):
I use MvvmCross for develop a CrossPlatform App.
I work on my Mac and I have not errors when I build my solution.
When I run it... I have this error : failed to find constructor for type Cirrious.MvvmCross.ViewModels.MvxViewModelLoader and highlights base.ViewDidLoad();
Code :
public partial class MainView : MvxViewController
{
static bool UserInterfaceIdiomIsPhone {
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}
public MainView ()
: base (UserInterfaceIdiomIsPhone ? "MainView_iPhone" : "MainView_iPad", null)
{
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
}
It's a default code, I just changed super-class (UIViewController to MvxViewController)
Stacktrace :
Failed to find constructor for type Cirrious.MvvmCross.ViewModels.MvxViewModelLoader
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer+ConstructingResolver.Resolve () [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, ResolveOptions resolveOptions, System.Object& resolved) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Object& resolved) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve (System.Type t) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve[IMvxViewModelLoader] () [0x00000] in :0
at Cirrious.CrossCore.Mvx.Resolve[IMvxViewModelLoader] () [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.LoadViewModel (IMvxTouchView touchView) [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods+<>c_DisplayClass1.b_0 () [0x00000] in :0
at Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate (IMvxView view, System.Func`1 viewModelLoader) [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.OnViewCreate (IMvxTouchView touchView) [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerAdapter.HandleViewDidLoadCalled (System.Object sender, System.EventArgs e) [0x00000] in :0
at (wrapper delegate-invoke) :invoke_void_this__object_EventArgs (object,System.EventArgs)
at Cirrious.CrossCore.Core.MvxDelegateExtensionMethods.Raise (System.EventHandler eventHandler, System.Object sender) [0x00000] in :0
at Cirrious.CrossCore.Touch.Views.MvxEventSourceViewController.ViewDidLoad () [0x00000] in :0
at TrainingCatalog.Touch.MainView.ViewDidLoad () [0x00002] in /Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/Views/MainView.cs:30
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00008] in /Developer/MonoTouch/Source/monotouch/src/UIKit/.pp-UIWindow.g.cs:129
at TrainingCatalog.Touch.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0003c] in /Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/AppDelegate.cs:21
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/.pp-UIApplication.cs:38
at TrainingCatalog.Touch.Application.Main (System.String[] args) [0x00008] in /Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/Main.cs:17
Failed to find constructor for type Cirrious.MvvmCross.ViewModels.MvxViewModelLoader
From the stack trace, I'm guessing the line that is failing is: https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxViewControllerExtensionMethods.cs#L44
This is looking in IoC for a type which has been registered in setup as:
protected virtual void InitializeViewModelFramework()
{
Mvx.RegisterType<IMvxViewModelLoader, MvxViewModelLoader>();
}
(from https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/Platform/MvxSetup.cs#L192)
Looking at MvxViewModelLoader, this is defined in: https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/ViewModels/MvxViewModelLoader.cs - so it should have a default public parameterless constructor added by the compiler...
With this in mind...
I'm guessing that maybe Xamarin is stripping out the constructor from your deployed binaries. This might be because of your linker settings - so please check that you have set the linker to link "SDK only". But if that doesn't help then this might be down to some Xamarin optimisation/feature - so you might need to .
As a simple workaround you could try overriding Setup so that you use:
protected override void InitializeViewModelFramework()
{
Mvx.RegisterSingleton<IMvxViewModelLoader>(() => new MvxViewModelLoader>());
}
However, even if this works, then I'd be worried that the linker might be stripping out other symbols in your app - so this might not be enough... you might need to chase this through with Xamarin.
I am using xamarin android 4.10.1 and GooglePlayServices Rev. 12 from xamarin component store. It is mvvmcross application, so I have Core and Android projects. I need push notifications support in my app. So I start with GooglePlayServices component. I write this code:
var gcm = GoogleCloudMessaging.GetInstance(this);
var key = gcm.Register(new[] { "senderId" });
and it doesn't work, I fount that I need to run it on async thread, one solution I found here: http://forums.xamarin.com/discussion/8420/error-calling-googlecloudmessaging-register
ThreadPool.QueueUserWorkItem(o =>
{
var gcm = GoogleCloudMessaging.GetInstance(this);
var key = gcm.Register(new[] { Settings.GmcSenderId });
});
This code works, my service handle registration message, but I need this registration key in my mvvmcross ViewModel. So I start to register with Task approach:
var task = Task.Factory.Startnew(() =>
{
var gcm = GoogleCloudMessaging.GetInstance(this);
return gcm.Register(new[] { Settings.GmcSenderId });
});
var key = task.Result; // wait for result
// key is needed to execute code here
// ViewModel.Key = key;
But every time I receive SERVICE_NOT_AVAILABLE Exception, also I have try to sync with ManualResetEvent object, but still have exceptions.
Maybe some one know solution, how to bring registration Id to ViewModel class from View (activity). Or maybe you have some example with mvvmcross and receiving registration Id in view model...
My code with Task:
public string Register(string senderId)
{
var task = Task.Factory.StartNew(() =>
{
var context = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity;
var gcm = GoogleCloudMessaging.GetInstance(context);
return gcm.Register(senderId);
});
return task.Result; // exception here!
}
Detailed exception:
InnerException {Java.IO.IOException: Exception of type 'Java.IO.IOException' was thrown.
at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00064] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.10.1-branch/d23a19bf/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:194
at Android.Gms.Gcm.GoogleCloudMessaging.Register (System.String[] p0) [0x00000] in <filename unknown>:0
at Fiocx.Android.Code.NotificationService+<>c__DisplayClass1.<Register>b__0 () [0x00013] in d:\ASUS\Work\Programming\.NET\Fiocx.CloudApp\mobile_src\Fiocx.Mobile\Fiocx.Android\Code\NotificationService.cs:33
at System.Threading.Tasks.TaskActionInvoker+FuncInvoke`1[System.String].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in <filename unknown>:0
at System.Threading.Tasks.Task.InnerInvoke () [0x00000] in <filename unknown>:0
at System.Threading.Tasks.Task.ThreadStart () [0x00000] in <filename unknown>:0
--- End of managed exception stack trace ---
java.io.IOException: SERVICE_NOT_AVAILABLE
at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
at dalvik.system.NativeStart.run(Native Method)
} Java.IO.IOException
Similar problem with a solution: GCM SERVICE_NOT_AVAILABLE on Android 2.2
Btw have you tried using PushSharp?
https://github.com/Redth/PushSharp