Casting Exception in LoadApplication when using LightInject
I'm new to Xamarin Forms and LightInject.
I'm getting an exeption :
System.InvalidCastException: Specified cast is not valid.
when calls
LoadApplication(new App()); in MainActivity.cs
when calling the instance as a NavigationPage this happens. I tried
MainPage = instance
and it works fine. But I need to send the instance as a NavigationPage
Do you have any idea why this happens?
var container = new ServiceContainer();
container.Register<WardListPage>();
container.Register<WardListViewModel>();
container.Register<WardListService>();
container.Register<PatientListViewPage>();
container.Register<PatientListViewModel>();
container.Register<PatientService>();
container.Register<PatientDetailsViewPage>();
container.Register<PatientDetailsViewModel>();
var instance = container.GetInstance<WardListPage>();
MainPage = new NavigationPage(instance); //here the issue comes
Here is the Stacktrace
Here're the Exception Details
12-30 09:26:37.554 I/mono-stdout(18434): System.InvalidCastException: Specified cast is not valid.
System.InvalidCastException: Specified cast is not valid.
12-30 09:26:37.558 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.RegisterChildPage (Xamarin.Forms.Page page) [0x0001c] in <3a9c335d80a748a29a8f8588acbed83f>:0 at Xamarin.Forms.Internals.ToolbarTracker.RegisterChildPage (Xamarin.Forms.Page page) [0x0001c] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Internals.EnumerableExtensions.ForEach[T] (System.Collections.Generic.IEnumerable1[T] enumeration, System.Action
1[T] action) [0x00010] in <3a9c335d80a748a29a8f8588acbed83f>:0 12-30 09:26:37.560 I/mono-stdout(18434): at Xamarin.Forms.Internals.EnumerableExtensions.ForEach[T] (System.Collections.Generic.IEnumerable1[T] enumeration, System.Action
1[T] action) [0x00010] in <3a9c335d80a748a29a8f8588acbed83f>:0
12-30 09:26:37.561 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.TrackTarget (Xamarin.Forms.Page page) [0x00041] in <3a9c335d80a748a29a8f8588acbed83f>:0 at Xamarin.Forms.Internals.ToolbarTracker.TrackTarget (Xamarin.Forms.Page page) [0x00041] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Internals.ToolbarTracker.set_Target (Xamarin.Forms.Page value) [0x00025] in <3a9c335d80a748a29a8f8588acbed83f>:0 12-30 09:26:37.563 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.set_Target (Xamarin.Forms.Page value) [0x00025] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1[TElement] e) [0x000fe] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.565 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs
1[TElement] e) [0x000fe] in <02db0bcb95874f4db06b80f38eac4adf>:0
at FormsControls.Droid.AppCompatAnimationNavRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1[TElement] e) [0x00000] in <9cf8e9b117d44fb7a184e024868cb7a5>:0 12-30 09:26:37.567 I/mono-stdout(18434): at FormsControls.Droid.AppCompatAnimationNavRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs
1[TElement] e) [0x00000] in <9cf8e9b117d44fb7a184e024868cb7a5>:0
at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetElement (TElement element) [0x000dd] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.569 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[TElement].SetElement (TElement element) [0x000dd] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.571 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.573 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.575 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page page, System.Boolean layout) [0x00009] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page page, System.Boolean layout) [0x00009] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.576 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00096] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00096] in <02db0bcb95874f4db06b80f38eac4adf>:0
at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00087] in <02db0bcb95874f4db06b80f38eac4adf>:0
at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x00052] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.578 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00087] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.580 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x00052] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x0000c] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.581 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x0000c] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x0026f] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.583 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x0026f] in <02db0bcb95874f4db06b80f38eac4adf>:0 at DipsDemoXaml.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0002f] in C:Usersmadura.dsourcereposDipsDemoXamlDipsDemoXamlDipsDemoXaml.AndroidMainActivity.cs:22
12-30 09:26:37.585 I/mono-stdout(18434): at DipsDemoXaml.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0002f] in C:Usersmadura.dsourcereposDipsDemoXamlDipsDemoXamlDipsDemoXaml.AndroidMainActivity.cs:22
c# dependency-injection xamarin.forms light-inject
add a comment |
I'm new to Xamarin Forms and LightInject.
I'm getting an exeption :
System.InvalidCastException: Specified cast is not valid.
when calls
LoadApplication(new App()); in MainActivity.cs
when calling the instance as a NavigationPage this happens. I tried
MainPage = instance
and it works fine. But I need to send the instance as a NavigationPage
Do you have any idea why this happens?
var container = new ServiceContainer();
container.Register<WardListPage>();
container.Register<WardListViewModel>();
container.Register<WardListService>();
container.Register<PatientListViewPage>();
container.Register<PatientListViewModel>();
container.Register<PatientService>();
container.Register<PatientDetailsViewPage>();
container.Register<PatientDetailsViewModel>();
var instance = container.GetInstance<WardListPage>();
MainPage = new NavigationPage(instance); //here the issue comes
Here is the Stacktrace
Here're the Exception Details
12-30 09:26:37.554 I/mono-stdout(18434): System.InvalidCastException: Specified cast is not valid.
System.InvalidCastException: Specified cast is not valid.
12-30 09:26:37.558 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.RegisterChildPage (Xamarin.Forms.Page page) [0x0001c] in <3a9c335d80a748a29a8f8588acbed83f>:0 at Xamarin.Forms.Internals.ToolbarTracker.RegisterChildPage (Xamarin.Forms.Page page) [0x0001c] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Internals.EnumerableExtensions.ForEach[T] (System.Collections.Generic.IEnumerable1[T] enumeration, System.Action
1[T] action) [0x00010] in <3a9c335d80a748a29a8f8588acbed83f>:0 12-30 09:26:37.560 I/mono-stdout(18434): at Xamarin.Forms.Internals.EnumerableExtensions.ForEach[T] (System.Collections.Generic.IEnumerable1[T] enumeration, System.Action
1[T] action) [0x00010] in <3a9c335d80a748a29a8f8588acbed83f>:0
12-30 09:26:37.561 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.TrackTarget (Xamarin.Forms.Page page) [0x00041] in <3a9c335d80a748a29a8f8588acbed83f>:0 at Xamarin.Forms.Internals.ToolbarTracker.TrackTarget (Xamarin.Forms.Page page) [0x00041] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Internals.ToolbarTracker.set_Target (Xamarin.Forms.Page value) [0x00025] in <3a9c335d80a748a29a8f8588acbed83f>:0 12-30 09:26:37.563 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.set_Target (Xamarin.Forms.Page value) [0x00025] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1[TElement] e) [0x000fe] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.565 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs
1[TElement] e) [0x000fe] in <02db0bcb95874f4db06b80f38eac4adf>:0
at FormsControls.Droid.AppCompatAnimationNavRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1[TElement] e) [0x00000] in <9cf8e9b117d44fb7a184e024868cb7a5>:0 12-30 09:26:37.567 I/mono-stdout(18434): at FormsControls.Droid.AppCompatAnimationNavRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs
1[TElement] e) [0x00000] in <9cf8e9b117d44fb7a184e024868cb7a5>:0
at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetElement (TElement element) [0x000dd] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.569 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[TElement].SetElement (TElement element) [0x000dd] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.571 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.573 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.575 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page page, System.Boolean layout) [0x00009] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page page, System.Boolean layout) [0x00009] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.576 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00096] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00096] in <02db0bcb95874f4db06b80f38eac4adf>:0
at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00087] in <02db0bcb95874f4db06b80f38eac4adf>:0
at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x00052] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.578 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00087] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.580 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x00052] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x0000c] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.581 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x0000c] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x0026f] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.583 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x0026f] in <02db0bcb95874f4db06b80f38eac4adf>:0 at DipsDemoXaml.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0002f] in C:Usersmadura.dsourcereposDipsDemoXamlDipsDemoXamlDipsDemoXaml.AndroidMainActivity.cs:22
12-30 09:26:37.585 I/mono-stdout(18434): at DipsDemoXaml.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0002f] in C:Usersmadura.dsourcereposDipsDemoXamlDipsDemoXamlDipsDemoXaml.AndroidMainActivity.cs:22
c# dependency-injection xamarin.forms light-inject
1
Please post the full exception details, including stack trace.
– Steven
Dec 27 '18 at 15:24
@Steven hi, Thanks for replying. Here is the Stacktrace
– Dumindu De Silva
Jan 1 at 3:40
add a comment |
I'm new to Xamarin Forms and LightInject.
I'm getting an exeption :
System.InvalidCastException: Specified cast is not valid.
when calls
LoadApplication(new App()); in MainActivity.cs
when calling the instance as a NavigationPage this happens. I tried
MainPage = instance
and it works fine. But I need to send the instance as a NavigationPage
Do you have any idea why this happens?
var container = new ServiceContainer();
container.Register<WardListPage>();
container.Register<WardListViewModel>();
container.Register<WardListService>();
container.Register<PatientListViewPage>();
container.Register<PatientListViewModel>();
container.Register<PatientService>();
container.Register<PatientDetailsViewPage>();
container.Register<PatientDetailsViewModel>();
var instance = container.GetInstance<WardListPage>();
MainPage = new NavigationPage(instance); //here the issue comes
Here is the Stacktrace
Here're the Exception Details
12-30 09:26:37.554 I/mono-stdout(18434): System.InvalidCastException: Specified cast is not valid.
System.InvalidCastException: Specified cast is not valid.
12-30 09:26:37.558 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.RegisterChildPage (Xamarin.Forms.Page page) [0x0001c] in <3a9c335d80a748a29a8f8588acbed83f>:0 at Xamarin.Forms.Internals.ToolbarTracker.RegisterChildPage (Xamarin.Forms.Page page) [0x0001c] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Internals.EnumerableExtensions.ForEach[T] (System.Collections.Generic.IEnumerable1[T] enumeration, System.Action
1[T] action) [0x00010] in <3a9c335d80a748a29a8f8588acbed83f>:0 12-30 09:26:37.560 I/mono-stdout(18434): at Xamarin.Forms.Internals.EnumerableExtensions.ForEach[T] (System.Collections.Generic.IEnumerable1[T] enumeration, System.Action
1[T] action) [0x00010] in <3a9c335d80a748a29a8f8588acbed83f>:0
12-30 09:26:37.561 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.TrackTarget (Xamarin.Forms.Page page) [0x00041] in <3a9c335d80a748a29a8f8588acbed83f>:0 at Xamarin.Forms.Internals.ToolbarTracker.TrackTarget (Xamarin.Forms.Page page) [0x00041] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Internals.ToolbarTracker.set_Target (Xamarin.Forms.Page value) [0x00025] in <3a9c335d80a748a29a8f8588acbed83f>:0 12-30 09:26:37.563 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.set_Target (Xamarin.Forms.Page value) [0x00025] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1[TElement] e) [0x000fe] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.565 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs
1[TElement] e) [0x000fe] in <02db0bcb95874f4db06b80f38eac4adf>:0
at FormsControls.Droid.AppCompatAnimationNavRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1[TElement] e) [0x00000] in <9cf8e9b117d44fb7a184e024868cb7a5>:0 12-30 09:26:37.567 I/mono-stdout(18434): at FormsControls.Droid.AppCompatAnimationNavRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs
1[TElement] e) [0x00000] in <9cf8e9b117d44fb7a184e024868cb7a5>:0
at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetElement (TElement element) [0x000dd] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.569 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[TElement].SetElement (TElement element) [0x000dd] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.571 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.573 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.575 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page page, System.Boolean layout) [0x00009] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page page, System.Boolean layout) [0x00009] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.576 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00096] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00096] in <02db0bcb95874f4db06b80f38eac4adf>:0
at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00087] in <02db0bcb95874f4db06b80f38eac4adf>:0
at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x00052] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.578 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00087] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.580 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x00052] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x0000c] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.581 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x0000c] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x0026f] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.583 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x0026f] in <02db0bcb95874f4db06b80f38eac4adf>:0 at DipsDemoXaml.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0002f] in C:Usersmadura.dsourcereposDipsDemoXamlDipsDemoXamlDipsDemoXaml.AndroidMainActivity.cs:22
12-30 09:26:37.585 I/mono-stdout(18434): at DipsDemoXaml.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0002f] in C:Usersmadura.dsourcereposDipsDemoXamlDipsDemoXamlDipsDemoXaml.AndroidMainActivity.cs:22
c# dependency-injection xamarin.forms light-inject
I'm new to Xamarin Forms and LightInject.
I'm getting an exeption :
System.InvalidCastException: Specified cast is not valid.
when calls
LoadApplication(new App()); in MainActivity.cs
when calling the instance as a NavigationPage this happens. I tried
MainPage = instance
and it works fine. But I need to send the instance as a NavigationPage
Do you have any idea why this happens?
var container = new ServiceContainer();
container.Register<WardListPage>();
container.Register<WardListViewModel>();
container.Register<WardListService>();
container.Register<PatientListViewPage>();
container.Register<PatientListViewModel>();
container.Register<PatientService>();
container.Register<PatientDetailsViewPage>();
container.Register<PatientDetailsViewModel>();
var instance = container.GetInstance<WardListPage>();
MainPage = new NavigationPage(instance); //here the issue comes
Here is the Stacktrace
Here're the Exception Details
12-30 09:26:37.554 I/mono-stdout(18434): System.InvalidCastException: Specified cast is not valid.
System.InvalidCastException: Specified cast is not valid.
12-30 09:26:37.558 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.RegisterChildPage (Xamarin.Forms.Page page) [0x0001c] in <3a9c335d80a748a29a8f8588acbed83f>:0 at Xamarin.Forms.Internals.ToolbarTracker.RegisterChildPage (Xamarin.Forms.Page page) [0x0001c] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Internals.EnumerableExtensions.ForEach[T] (System.Collections.Generic.IEnumerable1[T] enumeration, System.Action
1[T] action) [0x00010] in <3a9c335d80a748a29a8f8588acbed83f>:0 12-30 09:26:37.560 I/mono-stdout(18434): at Xamarin.Forms.Internals.EnumerableExtensions.ForEach[T] (System.Collections.Generic.IEnumerable1[T] enumeration, System.Action
1[T] action) [0x00010] in <3a9c335d80a748a29a8f8588acbed83f>:0
12-30 09:26:37.561 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.TrackTarget (Xamarin.Forms.Page page) [0x00041] in <3a9c335d80a748a29a8f8588acbed83f>:0 at Xamarin.Forms.Internals.ToolbarTracker.TrackTarget (Xamarin.Forms.Page page) [0x00041] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Internals.ToolbarTracker.set_Target (Xamarin.Forms.Page value) [0x00025] in <3a9c335d80a748a29a8f8588acbed83f>:0 12-30 09:26:37.563 I/mono-stdout(18434): at Xamarin.Forms.Internals.ToolbarTracker.set_Target (Xamarin.Forms.Page value) [0x00025] in <3a9c335d80a748a29a8f8588acbed83f>:0
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1[TElement] e) [0x000fe] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.565 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs
1[TElement] e) [0x000fe] in <02db0bcb95874f4db06b80f38eac4adf>:0
at FormsControls.Droid.AppCompatAnimationNavRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs1[TElement] e) [0x00000] in <9cf8e9b117d44fb7a184e024868cb7a5>:0 12-30 09:26:37.567 I/mono-stdout(18434): at FormsControls.Droid.AppCompatAnimationNavRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs
1[TElement] e) [0x00000] in <9cf8e9b117d44fb7a184e024868cb7a5>:0
at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].SetElement (TElement element) [0x000dd] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.569 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[TElement].SetElement (TElement element) [0x000dd] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.571 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.VisualElementRenderer
1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.573 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.575 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page page, System.Boolean layout) [0x00009] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page page, System.Boolean layout) [0x00009] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.576 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00096] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00096] in <02db0bcb95874f4db06b80f38eac4adf>:0
at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00087] in <02db0bcb95874f4db06b80f38eac4adf>:0
at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x00052] in <02db0bcb95874f4db06b80f38eac4adf>:0 12-30 09:26:37.578 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00087] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.580 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x00052] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x0000c] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.581 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x0000c] in <02db0bcb95874f4db06b80f38eac4adf>:0 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x0026f] in <02db0bcb95874f4db06b80f38eac4adf>:0
12-30 09:26:37.583 I/mono-stdout(18434): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x0026f] in <02db0bcb95874f4db06b80f38eac4adf>:0 at DipsDemoXaml.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0002f] in C:Usersmadura.dsourcereposDipsDemoXamlDipsDemoXamlDipsDemoXaml.AndroidMainActivity.cs:22
12-30 09:26:37.585 I/mono-stdout(18434): at DipsDemoXaml.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0002f] in C:Usersmadura.dsourcereposDipsDemoXamlDipsDemoXamlDipsDemoXaml.AndroidMainActivity.cs:22
c# dependency-injection xamarin.forms light-inject
c# dependency-injection xamarin.forms light-inject
edited Jan 1 at 3:56
Dumindu De Silva
asked Dec 27 '18 at 6:37
Dumindu De SilvaDumindu De Silva
215
215
1
Please post the full exception details, including stack trace.
– Steven
Dec 27 '18 at 15:24
@Steven hi, Thanks for replying. Here is the Stacktrace
– Dumindu De Silva
Jan 1 at 3:40
add a comment |
1
Please post the full exception details, including stack trace.
– Steven
Dec 27 '18 at 15:24
@Steven hi, Thanks for replying. Here is the Stacktrace
– Dumindu De Silva
Jan 1 at 3:40
1
1
Please post the full exception details, including stack trace.
– Steven
Dec 27 '18 at 15:24
Please post the full exception details, including stack trace.
– Steven
Dec 27 '18 at 15:24
@Steven hi, Thanks for replying. Here is the Stacktrace
– Dumindu De Silva
Jan 1 at 3:40
@Steven hi, Thanks for replying. Here is the Stacktrace
– Dumindu De Silva
Jan 1 at 3:40
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53940786%2fcasting-exception-in-loadapplication-when-using-lightinject%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53940786%2fcasting-exception-in-loadapplication-when-using-lightinject%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Please post the full exception details, including stack trace.
– Steven
Dec 27 '18 at 15:24
@Steven hi, Thanks for replying. Here is the Stacktrace
– Dumindu De Silva
Jan 1 at 3:40