I'm brand new to Xamarin and not super experienced with C#. I installed the Xamarin XCalendar plugin and am attempting to implement the EventCalendarExample Sample code (see GitHub here) to better understand how this code works and to learn how to modify it and use it. I did some research on calendar plugins for Xamarin and liked this one as it showed how to use it. Some of the others I looked at did not have much documentation or sample code to look at.
I implemented the code exactly as-is in my project but, when I go to click on the calendar tab when debugging the code, I receive the following error:
System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'
My files for the following are as implemented in the GitHub:
My AppShell.xaml is below. Please note that my EventCalendarExamplePage is named EventManagerPage.
<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:PPA.Views"
Title="PPA"
x:Class="PPA.AppShell"
>
<!--
The overall app visual hierarchy is defined here, along with navigation.
https://learn.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/
-->
<Shell.Resources>
<ResourceDictionary>
<Style x:Key="BaseStyle" TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="Shell.ForegroundColor" Value="White" />
<Setter Property="Shell.TitleColor" Value="White" />
<Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
<Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="Shell.TabBarForegroundColor" Value="White"/>
<Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
<Setter Property="Shell.TabBarTitleColor" Value="White"/>
</Style>
<Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
<Style TargetType="FlyoutItem" BasedOn="{StaticResource BaseStyle}" />
</ResourceDictionary>
</Shell.Resources>
<TabBar>
<ShellContent Title="Tasks" Icon="icon_about.png" Route="TaskManagerPage" ContentTemplate="{DataTemplate local:TaskManagerPage}" />
<ShellContent Title="Events" Icon="icon_about.png" Route="EventManagerPage" ContentTemplate="{DataTemplate local:EventManagerPage}" />
<ShellContent Title="Reminders" Icon="icon_about.png" Route="ReminderManagerPage" ContentTemplate="{DataTemplate local:ReminderManagerPage}"/>
</TabBar>
</Shell>
I've looked around and haven't seen anyone else with this error. Any info or suggestions would be greatly appreciated!
Note - this is the only text I see in the Output pane when I click on the calendar tab in the emulator.
[OpenGLRenderer] Davey! duration=1240ms; Flags=0, IntendedVsync=16577769666564, Vsync=16577769666564, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=16577772074980, AnimationStart=16577772093180, PerformTraversalsStart=16577772332780, DrawStart=16577773064980, SyncQueued=16577774097980, SyncStart=16577775454680, IssueDrawCommandsStart=16577775647080, SwapBuffers=16579009952980, FrameCompleted=16579011771880, DequeueBufferDuration=449700, QueueBufferDuration=929200, GpuCompleted=0,
[TabLayout] MODE_SCROLLABLE + GRAVITY_FILL is not supported, GRAVITY_START will be used instead
**System.Reflection.TargetInvocationException:** 'Exception has been thrown by the target of an invocation.'
I looked for a stack trace or something with more information but this is all I could find. The Error List does not have anything and the Call Stack tab only says [External Code]. When I click "copy details" from the exception box as suggested, I get the following and nothing else.
System.Reflection.TargetInvocationException Message=Exception has been thrown by the target of an invocation.
Turns out I was missing some of the static resources referenced which was causing it to break. Thank you ToolmakerSteve for more info on the innerexception. I did not realize this exception had any internal components.
I was able to wrap the component initialization in a try-catch and print the exception in a popup box as a .ToString() when thrown. It's weird VS showed the stacktrace as External Code but I'm glad this worked to see more info about the exception.