I try to use the SfDataGrid in a Xamarin project (.net standard 2.0 as shared code which includes the views) with paging.
The Android project works fine under Android 7.1.2 (LineageOS 14.1) on my Motorola G4.
But the UWP project crashes. In debug output of Visual Studio 2017 I see the following exception:
Exception thrown: 'System.Reflection.TargetException' in System.Private.CoreLib.dll
System.Reflection.TargetException: Exception of type 'System.Reflection.TargetException' was thrown.
at System.Reflection.RuntimeMethodInfo.ThrowNoInvokeException()
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Xamarin.Forms.ImageSource.FromResource(String resource, Assembly sourceAssembly)
at Syncfusion.SfDataGrid.XForms.DataPager.AppearanceManager.GetFirstPageIcon()
at Syncfusion.SfDataGrid.XForms.DataPager.Header.CreateHeaderContent()
at Syncfusion.SfDataGrid.XForms.DataPager.Header..ctor(SfDataPager pager)
at Syncfusion.SfDataGrid.XForms.DataPager.SfDataPager..ctor()
at Foo.BarPage.InitializeComponent()
at Foo.BarPage..ctor()
All projects include the Nuget package. Any ideas why this fails? For the Android project I can step trough the custom Behavior class where I set the Grid and Pager and the source, but in UWP I only see this exception where loading of the icons for the paging buttons fails but the behavior code is never called/debugger never stops at breakpoint in OnAttachedTo.
Any idea what is wrong or how to fix it?
// Edit 2018-03-13
When I compare the file versions I see version 16.1451.0.26 for Android for Syncfusion.SfDataGrid.XForms.Android.dll and Syncfusion.SfDataGrid.XForms.dll. But for UWP, there is a mismatch. Syncfusion.SfDataGrid.XForms.UWP.dll has version 16.1460.0.26 while Syncfusion.SfDataGrid.XForms.dll has 16.1451.0.26. so the 60 to 51 mismatch seam to cause the issue under UWP and this would explain why the Android app works, because here the DLLs have same version.
Does anyone know if app.config with assemblyBinding still works in UWP to workaround this version mismatch and force using the DLLs together with different version?
// Edit 2018-04-04
I tried to investigate it more, got the source code for Syncfusion Xamarin components, modified them to use the last Xamarin version 2.5.0.280555 Service Release 5 and added the projects directly to my solution, but I still get the same error.
And the issue happens directly when I follow the paging guide:
Create a new SfDataPager instance
This triggers the exception directly:
var appearanceManager = new CustomAppearance();
var dataPager = new SfDataPager
{
AppearanceManager = appearanceManager
};
causes System.Reflection.TargetException:
System.Reflection.TargetException: Exception of type 'System.Reflection.TargetException' was thrown.
at System.Reflection.RuntimeMethodInfo.ThrowNoInvokeException()
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Xamarin.Forms.ImageSource.FromResource(String resource, Assembly sourceAssembly)
at Syncfusion.SfDataGrid.XForms.DataPager.AppearanceManager.GetFirstPageIcon()
at Syncfusion.SfDataGrid.XForms.DataPager.Header.CreateHeaderContent()
at Syncfusion.SfDataGrid.XForms.DataPager.Header..ctor(SfDataPager pager)
at Syncfusion.SfDataGrid.XForms.DataPager.SfDataPager..ctor()
but in CustomAppearance class I override the GetIcons methods (GetFirstPageIcon, GetLastPageIcon, GetNextPageIcon, GetPreviousPageIcon)
public class CustomAppearance : AppearanceManager
{
public override ImageSource GetFirstPageIcon()
{
var image = ImageSource.FromResource("App.Resources.FirstPageIcon.png");
return image;
}
public override ImageSource GetLastPageIcon()
{
var image = ImageSource.FromResource("App.Resources.LastPageIcon.png");
return image;
}
public override ImageSource GetNextPageIcon()
{
var image = ImageSource.FromResource("App.Resources.NextPageIcon.png");
return image;
}
public override ImageSource GetPreviousPageIcon()
{
var image = ImageSource.FromResource("App.Resources.PrevPageIcon.png");
return image;
}
}
and in Android everything works fine. Here I can step through all overrides and get my custom images and they show in the Pager. And in the UWP project I get the crash.
I also followed the steps which should be done in Release mode only, to load the assemblies:
List<Assembly> assembliesToInclude = new List<Assembly>();
//Now, add all the assemblies your app uses
assembliesToInclude.Add(typeof(SfDataGridRenderer).GetTypeInfo().Assembly);
assembliesToInclude.Add(typeof(SfDataPager).GetTypeInfo().Assembly);
Xamarin.Forms.DependencyService.Register<SfDataGridRenderer>();
Xamarin.Forms.DependencyService.Register<SfDataPager>();
// replaces Xamarin.Forms.Forms.Init(e);
Xamarin.Forms.Forms.Init(e, assembliesToInclude);
So the DLLs Syncfusion.SfDataGrid.XForms.dll and Syncfusion.SfDataGrid.XForms.UWP.dll are loaded but loading the images from the Syncfusion.SfDataGrid.XForms.dll fails:
I'm now out of ideas.
