【发布时间】:2018-08-03 09:12:45
【问题描述】:
我尝试在 Xamarin 项目(.net 标准 2.0 作为包含视图的共享代码)中使用 SfDataGrid 和 paging。
Android 项目在我的 Motorola G4 上的 Android 7.1.2 (LineageOS 14.1) 下运行良好。
但是 UWP 项目崩溃了。在 Visual Studio 2017 的调试输出中,我看到以下异常:
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()
所有项目include the Nuget package。任何想法为什么会失败?对于 Android 项目,我可以通过自定义 Behavior 类来设置 Grid 和 Pager 以及源,但在 UWP 中,我只看到这个异常,其中加载分页按钮的图标失败,但从不调用行为代码/调试器永远不会在OnAttachedTo 的断点处停止。
知道出了什么问题或如何解决吗?
// 编辑 2018-03-13
当我比较文件版本时,我看到Syncfusion.SfDataGrid.XForms.Android.dll 和Syncfusion.SfDataGrid.XForms.dll 的Android 版本16.1451.0.26。但对于 UWP,存在不匹配。 Syncfusion.SfDataGrid.XForms.UWP.dll 的版本为 16.1460.0.26,而 Syncfusion.SfDataGrid.XForms.dll 的版本为 16.1451.0.26。所以 60 到 51 不匹配的接缝会导致 UWP 下的问题,这可以解释为什么 Android 应用程序可以工作,因为这里的 DLL 具有相同的版本。
有谁知道带有assemblyBinding 的 app.config 是否仍可在 UWP 中工作以解决此版本不匹配问题并强制将 DLL 与不同版本一起使用?
// 编辑 2018-04-04
我尝试对其进行更多调查,获得了 Syncfusion Xamarin 组件的源代码,将它们修改为使用最新的 Xamarin 版本 2.5.0.280555 Service Release 5,并将项目直接添加到我的解决方案中,但我仍然遇到同样的错误。
问题发生在directly when I follow the paging guide:
创建一个新的 SfDataPager 实例
这会直接触发异常:
var appearanceManager = new CustomAppearance();
var dataPager = new SfDataPager
{
AppearanceManager = appearanceManager
};
原因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()
但在 CustomAppearance 类中,我重写了 GetIcons 方法(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;
}
}
在 Android 中一切正常。在这里,我可以逐步完成所有覆盖并获取我的自定义图像,并将它们显示在寻呼机中。在 UWP 项目中,我遇到了崩溃。
我也followed the steps which should be done in Release mode only,来加载程序集:
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);
因此,DLL Syncfusion.SfDataGrid.XForms.dll 和 Syncfusion.SfDataGrid.XForms.UWP.dll 已加载,但从 Syncfusion.SfDataGrid.XForms.dll 加载图像失败:
我现在没有主意了。
【问题讨论】:
-
能否提供发生崩溃的代码?
-
@sme 崩溃发生在 .g.cs 文件中的 InitializeComponent() 处。在这里,我可以单步执行来自使用的控件的所有条目,但是当我离开 InitializeComponent 方法时,异常处理程序会处理异常。
-
你试过这个代码sample.
-
@NicoZhu-MSFT 这个演示没有使用 SfDataPager 所以它没有问题。
标签: datagrid xamarin.forms windows-10 syncfusion xamarin.uwp